2014-11-03 150 views
-1

我在尋找一個正則表達式模式,它匹配除一個確切單詞外的所有內容。正則表達式:匹配除一個單詞外的所有內容

例如,分辨率:

monitors/resolutions // Should not match 
monitors/34   // Should match 
monitors/foobar  // Should match 

我知道,你可以排除單個字符的列表,但你如何排除一個完整的字?

+1

的可能重複的[A正則表達式來排除字/串(http://stackoverflow.com/questions/2078915/a-regular-expression-to-exclude-a-word-string) – 2014-11-03 11:34:10

+1

這是這裏最常問到的問題之一,請在詢問之前進行搜索。 – 2014-11-03 11:34:28

回答

1

使用負前向斷言,

^(?!.*resolutions).*$ 

OR

^(?!.*\bresolutions\b).*$ 

DEMO

相關問題