我正在尝试创建一个正则表达式来检测 Markdown 引用 block 。
到目前为止,这是我的正则表达式:
(?:^|\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 `>`
一切正常,除了负向前瞻:如果遇到超过 2 个换行符,捕获就会停止。
Regex101当我想要 3 个时,显示 4 个匹配。有什么指示吗?
最佳答案
我相信您的问题在这里:
(?!\n(\s*\n)+[^>])
[^>]
与 \n
匹配。将其更改为:
(?!\n(\s*\n)+[^>\s])
关于javascript - 正则表达式匹配多个空格直到一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23682320/