2011-02-08 80 views

回答

7

根據引擎的不同,可以使用前視聲明。

\(((?:(?!foo)[^)])+)\) 

該正則表達式匹配一個括號字符串,其中字符串裏面的人物永遠不要匹配子表達式「富」(在這種情況下只是一個字符串)。

這是展開形式:

\(   # match the opening (
    (  # capture the text inside the parens 
    (?:  # we need another group, but don't capture it 
    (?!foo) # fail if the sub-expression "foo" matches at this point 
    [^)] # match a non-paren character 
    )+  # repeat that group 
)   # end the capture 
\)   # end the parens 
相關問題