看板 PHP 關於我們 聯絡資訊
※ 引述《zi (Play, Now)》之銘言: : 原po的意思應該是 : $s1 = "this is not ok"; : $s2 = "this is ok"; : $r1 = preg_match($pat, $s1, $m); : $r2 = preg_match($pat, $s2, $m); : 求 $pat 使得 $r1 = 0 且 $r2 = 1 : 話說這個問題也是困擾我很久..:Q $s1 = "this is not ok"; $s2 = "this is ok"; $pat = '/\bnot\b/i'; //$pat說明 // i 忽略大小寫 // \b包住字串表示絕對要為not才算匹對,note就不算匹對 $r1 = !preg_match($pat, $s1, $m1); $r2 = !preg_match($pat, $s2, $m2); 如果只是要求得真假?那麼的確在前面加個!就好了@_@ -- 我的樂多網誌http://blog.roodo.com/liaosankai -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.105.48.168
liaosankai :補充一點,要match完整一點改用preg_match_all() 06/30 17:42
ihs :感謝熱心回答 06/30 18:03
ihs :自己問題問得太爛... 06/30 18:03
ihs :像一篇文章裡面有一堆句子 想抓"this點點點點ok"這句 06/30 18:04
ihs :但是"點點點點"裡面沒有not這三個字 這pattern怎麼寫 06/30 18:04
ihs :這邊文章可能有很多"this點點點點ok"但要的只是那些 06/30 18:06
ihs :"this點點點點ok" 裡面沒有not這三個字的句子 06/30 18:07
ihs :not 可能是一個單字 或是一句連續的話 06/30 18:12