2014-05-15 52 views
0

我試圖創建一個正則表達式來檢測降價引用塊。
這是迄今爲止我正則表達式:正則表達式匹配多個空格,直到一個字符

(?:^|\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個匹配,當我想3.任何指針?

+0

你您正則表達式的描述不符實際的正則表達式。具體來說,描述中的最後一行有一個「+」,它在實際的正則表達式中不存在。 –

回答

1

我相信您的問題就在這裏:

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

[^>]是匹配\n。它改成這樣:

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

http://regex101.com/r/mT4wC4

+0

完美謝謝! – hjef

相關問題