正则表达式匹配多个空格直到一个字符

时间:2014-05-15 15:16:04

标签: javascript regex

我试图创建一个可以检测降价报价块的正则表达式 到目前为止,这是我的正则表达式:

(?:^|\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向我展示了4个匹配。任何指针?

1 个答案:

答案 0 :(得分:1)

我相信你的问题在这里:

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

[^>]\n匹配。将其更改为:

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

http://regex101.com/r/mT4wC4