1

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

Simon
  • 22,637
  • 36
  • 92
  • 121

1 Answers1

1

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
  • 74,049
  • 16
  • 131
  • 175
  • 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. – Simon Aug 27 '10 at 14:03
  • Maybe you want to lookaround: http://www.regular-expressions.info/lookaround.html – Sjoerd Aug 27 '10 at 14:04