title: Match words in a string which are not in anchor of link with regex
body: <p>I'm trying to find some words (or expression: like two words) in a string which are not in the anchor of a link (the string contains html code and is usually utf-8 encoded). The plan is to replace those words with some links after that.</p>
  
  <p>I'm not really good with regex, i've searched the web and stackoverflow and found two regex patterns which help me, but each of them have an issue. I'm hoping someone can help me to combine those two example to get a good one.</p>
  
  <p>First pattern: <code>/('.$tag.')(?![^&lt;]*&lt;\/a&gt;)/is</code></p>
  
  <p>This pattern, finds the words, but if by example i'm trying to find "express" in the string:</p>
  
  <p><code>In computing, a regular expression provides a concise and flexible means...</code></p>
  
  <p>..i don't expect to find a match, however the match is found in the word "expression".</p>
  
  <p>Second pattern: <code>\'(?!((&lt;.*?)|(&lt;a.*?)))(\b'.$tag.'\b)(?!(([^&lt;&gt;]*?)&gt;)|([^&gt;]*?&lt;/a&gt;))\'is</code></p>
  
  <p>This pattern, doesn't have the previous issue, but if the word or expression, i'm trying to find has as a last character a special utf-8 character then i don't get a match.</p>
  
  <p>Example word: apă</p>
  
  <p>Example string: <code>...care transformă umiditatea din aer în apă potabilă. Dacă iniţial a fost creată pentru situaţia ţărilor...</code></p>