tags:

views:

45

answers:

2

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

A: 

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.

Sjoerd
i need it to use it in big regex then, so i exactly need to write something like `[^...]` becouse i need to mention `not that word` too.
Syom
Maybe you want to lookaround: http://www.regular-expressions.info/lookaround.html
Sjoerd
of course, Thanks:)
Syom
A: 

The same question was already answered on stackoverflow (negating groups):

http://stackoverflow.com/questions/1240275/how-to-negate-specific-word-in-regex

DASPRiD