title: How to use regex to delete everything except some words?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5463348/regular-expression-match-all-words-except">Regular expression: match all words except</a>  </p>
  </blockquote>
  
  
  
  <p>I need your help for using Regex in PHP to negate a selection. So I have a string like this :
  "Hello my name is tom"</p>
  
  <p>What I need to do is to delete everything from this string witch is not "tom" or "jack" or "alex" so I tried :</p>
  
  <pre><code>$MyString = "Hello my name is tom"
  print_r(preg_replace('#^tom|^jack|^alex#i', '', $MyString));
  </code></pre>
  
  <p>But it's not working...</p>
  
  <p>Can you help me with that ?
  Thanks</p>