Skip to main content
Updated based on the revised question, and subsequent comments.
Source Link
phils
  • 53k
  • 3
  • 84
  • 127

Based on the screenshot, you are only interested in quotes spanning multiple lines. Here's a patten for that:

"\\(``\\(?:[^'\n]\\|'[^'\n]\\)*\\*'?\\)\n\\(?:.\\|\n\\)*?''"

Or in rx syntax:

(rx (seq (group "``" (zero-or-more (or (not (in "\n'"))
                                       (seq "'" (not (in "\n'")))))
                (zero-or-one "'"))
         "\n" (minimal-match (zero-or-more anything)) "''"))
 

Note that we handle single ' characters with this:

"\\(?:[^'\n]\\|'[^'\n]\\)*'?

Which says match zero-or-more repetitions of:

  1. Any single character which is neither ' nor a newline.
  2. A ' character followed by any single character which is neither ' nor a newline.

Followed optionally by a single ' immediately before the newline.


Group 1 is the part to highlight. e.g. with hi-lock-mode:

Hi-lock: (("\\(``\\(?:[^'\n]\\|'[^'\n]\\)*\\*'?\\)\n\\(?:.\\|\n\\)*?''"
           (1 (quote hi-green-b) prepend)))

Based on the screenshot, you are only interested in quotes spanning multiple lines. Here's a patten for that:

"\\(``\\(?:[^'\n]\\|'[^'\n]\\)*\\)\n\\(?:.\\|\n\\)*?''"

Or in rx syntax:

(rx (seq (group "``" (zero-or-more (or (not (in "\n'"))
                                       (seq "'" (not (in "\n'"))))))
         "\n" (minimal-match (zero-or-more anything)) "''"))

Group 1 is the part to highlight. e.g. with hi-lock-mode:

Hi-lock: (("\\(``\\(?:[^'\n]\\|'[^'\n]\\)*\\)\n\\(?:.\\|\n\\)*?''"
           (1 (quote hi-green-b) prepend)))

Based on the screenshot, you are only interested in quotes spanning multiple lines. Here's a patten for that:

"\\(``\\(?:[^'\n]\\|'[^'\n]\\)*'?\\)\n\\(?:.\\|\n\\)*?''"

Or in rx syntax:

(rx (seq (group "``" (zero-or-more (or (not (in "\n'"))
                                       (seq "'" (not (in "\n'")))))
                (zero-or-one "'"))
         "\n" (minimal-match (zero-or-more anything)) "''"))
 

Note that we handle single ' characters with this:

"\\(?:[^'\n]\\|'[^'\n]\\)*'?

Which says match zero-or-more repetitions of:

  1. Any single character which is neither ' nor a newline.
  2. A ' character followed by any single character which is neither ' nor a newline.

Followed optionally by a single ' immediately before the newline.


Group 1 is the part to highlight. e.g. with hi-lock-mode:

Hi-lock: (("\\(``\\(?:[^'\n]\\|'[^'\n]\\)*'?\\)\n\\(?:.\\|\n\\)*?''"
           (1 (quote hi-green-b) prepend)))
Updated based on the revised question, and subsequent comments.
Source Link
phils
  • 53k
  • 3
  • 84
  • 127

I can now see the basic problem is that I want to capture from `` (two back ticks) to the end of the line, but only when there are not two consecutive quote marks (i.e., closing quote is '').

Based on the screenshot, you are only interested in quotes spanning multiple lines. Here's a patten for that:

"``.*?\\(?:''\\|$\\)"
"\\(``\\(?:[^'\n]\\|'[^'\n]\\)*\\)\n\\(?:.\\|\n\\)*?''"

or equivalentlyOr in rx syntax:

(rx (seq "``"
         (minimal-match (zero-or-more not-newline))
         (or "''" eol)))
(rx (seq (group "``" (zero-or-more (or (not (in "\n'"))
                                       (seq "'" (not (in "\n'"))))))
         "\n" (minimal-match (zero-or-more anything)) "''"))

Group 1 is the part to highlight. e.g. with hi-lock-mode:

Hi-lock: (("\\(``\\(?:[^'\n]\\|'[^'\n]\\)*\\)\n\\(?:.\\|\n\\)*?''"
           (1 (quote hi-green-b) prepend)))

I can now see the basic problem is that I want to capture from `` (two back ticks) to the end of the line, but only when there are not two consecutive quote marks (i.e., closing quote is '').

"``.*?\\(?:''\\|$\\)"

or equivalently:

(rx (seq "``"
         (minimal-match (zero-or-more not-newline))
         (or "''" eol)))

Based on the screenshot, you are only interested in quotes spanning multiple lines. Here's a patten for that:

"\\(``\\(?:[^'\n]\\|'[^'\n]\\)*\\)\n\\(?:.\\|\n\\)*?''"

Or in rx syntax:

(rx (seq (group "``" (zero-or-more (or (not (in "\n'"))
                                       (seq "'" (not (in "\n'"))))))
         "\n" (minimal-match (zero-or-more anything)) "''"))

Group 1 is the part to highlight. e.g. with hi-lock-mode:

Hi-lock: (("\\(``\\(?:[^'\n]\\|'[^'\n]\\)*\\)\n\\(?:.\\|\n\\)*?''"
           (1 (quote hi-green-b) prepend)))
Formatting for clarity
Source Link
phils
  • 53k
  • 3
  • 84
  • 127

I can now see the basic problem is that I want to capture from `` (two back ticks) to the end of the line, but only when there are not two consecutive quote marks (i.e., closing quote is '').

"``.*?\\(?:''\\|$\\)"

or equivalently:

(rx (seq "``"
         (minimal-match (zero-or-more not-newline))
         (or "''" eol)))

I can now see the basic problem is that I want to capture from `` (two back ticks) to the end of the line, but only when there are not two consecutive quote marks (i.e., closing quote is '').

"``.*?\\(?:''\\|$\\)"

or equivalently:

(rx (seq "``" (minimal-match (zero-or-more not-newline)) (or "''" eol)))

I can now see the basic problem is that I want to capture from `` (two back ticks) to the end of the line, but only when there are not two consecutive quote marks (i.e., closing quote is '').

"``.*?\\(?:''\\|$\\)"

or equivalently:

(rx (seq "``"
         (minimal-match (zero-or-more not-newline))
         (or "''" eol)))
Added rx variant
Source Link
phils
  • 53k
  • 3
  • 84
  • 127
Loading
Source Link
phils
  • 53k
  • 3
  • 84
  • 127
Loading