문제

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?

도움이 되었습니까?

해결책

I believe your issue is here:

(?!\n(\s*\n)+[^>])

The [^>] is matching a \n. Change it to this:

(?!\n(\s*\n)+[^>\s])

http://regex101.com/r/mT4wC4

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top