^(?!My Words).*$
^(?!
手段尋找一個字符串的開頭,或符合多標誌,它後面沒有......
這就是爲什麼你必須先從「我的話」任何句子做在使用^
錨點時不匹配。
之所以y Words
取出^
錨時,匹配的是,現在你只是尋找字符串中的任何一點,後面沒有My Words
,這M
後的位置相匹配。
讓我們看看字符串My Words
以及(?!My Words).*$
如何應用於它。
請記住,^
是字符串的開始,即使你沒有把它放在你的正則表達式中,正則表達式引擎仍然會在那個位置開始。我會簡化它的一些工作原理。
首先正則表達式引擎步:
^My Words
|
Regex engine starts here, and looks if the current position onwards
matches (?!My Words), which it does not.
第二步:
^My Words
|
Regex engine evaluates the 'M', and finds that from this position
onwards also fails to match (?!My Words)
第三步:
^My Words
|
Standing at 'y', it finds that the lookahead now does not match 'My Words'.
This allows the rest of the pattern '.*$' to be applied, which matches
from 'y' till end of string.
這是什麼語言? – christopher
我正在使用.net正則表達式引擎這個鏈接,我正在使用測試.. http://www.regexplanet.com/advanced/dotnet/index.html –
你期望'^'做什麼? – JJJ