簡體   English   中英

正則表達式 - 如何匹配除嚴格的單詞之外的所有單詞?

[英]Regexp - How to match all words except strict ones?

我試圖找到一個排除特定單詞的正則表達式,但不包含包含它的單詞。

例如,如果我們排除“家”這個詞

home --> NOT OK
homefree -> OK
freehome -> OK

有任何想法嗎 ?

謝謝

我建議你看看Rexegg - Word Boundaries

如果你想匹配不包含“home”本身的行,你可以這樣做:

preg_match_all('/^(?!.*\bhome\b).*$/im', $str, $matches);

如果你想單獨匹配單詞:

preg_match_all('/\b(?!home\b)\w+/i', $str, $matches);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM