I believe your issue is here:
(?!\n(\s*\n)+[^>])
The [^>]
is matching a \n
. Change it to this:
(?!\n(\s*\n)+[^>\s])
Question
I'm trying to create a regex that will detect markdown quoting blocks.
Here is my regex so far:
(?:^|\n)[ \t]*(>[ \t]*\S(?:(?!\n(\s*\n)+[^>])[\s\S])*)
(?:^|\n) beginning of string, or a line break
[ \t]* optional spaces
>[ \t]*\S `>` followed by optional spaces and at least one character
( ... [\s\S])* capture any following character\white-space multiple times
(?!\n(\s*\n)+[^>]) stop capture if next following characters are
at least 2 line breaks mixed with other white-spaces
followed by anything but `>`
Everything works fine, except for the negative lookahead: the capture stops if more than 2 line breaks are encountered.
Regex101 shows me 4 matches when I want 3. Any pointers?
Solution
I believe your issue is here:
(?!\n(\s*\n)+[^>])
The [^>]
is matching a \n
. Change it to this:
(?!\n(\s*\n)+[^>\s])