开发者

match all except some word

开发者 https://www.devze.com 2023-01-13 16:07 出处:网络
i\'m looking for a way, to match all except the some word. please tell me how i must wrote it? when i wrote

i'm looking for a way, to match all except the some word.

please tell me how i must wrote it?

when i wrote

$str = "i am a programmer";
$word = "am";
preg_match_all("/[^($word)]/", $str, $matched);// it do the same, if i when i wrote
preg_match_all("/[^$word]/", $str, $matched);开发者_如何转开发

i also tried preg_match_all("/[^{$word}]/", $str, $matched); but it doesn't do the job.

how can i tell all except that word ?

Thanks Much


Can't you simply remove all occurrences of the word?

str_replace($word, '', $str);

Or split using explode() or preg_split()? This will give you an array with all parts separated by the word.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号