title: Check if a string contains a word but only in specific position?
body: <p>How can I check if a string contains a substring, but only in a specific position?</p>
  
  <p>Example string:</p>
  
  <blockquote>
    <p>What is your <strong>favorite</strong> color? my [<strong>favorite</strong>] color is blue</p>
  </blockquote>
  
  <p>If I wanted to check if the string contained a specific word I usually do this:</p>
  
  <pre><code>var
    S: string;
  begin
    S := 'What is your favorite color? my [favorite] color is blue';
    if (Pos('favorite', S) &gt; 0) then
    begin
      //
    end;
  end;
  </code></pre>
  
  <p>What I need is to determine if the word <strong>favorite</strong> exists in the string, ignoring though if it appears inside the [ ] symbols, which the above code sample clearly does not do.</p>
  
  <p>So if we put the code into a boolean function, some sample results would look like this:</p>
  
  <blockquote>
    <p>TRUE: What is your <strong>favorite</strong> color? my [<strong>my favorite</strong>] color is blue</p>
    
    <p>TRUE: What is your <strong>favorite</strong> color? my [<strong>blah blah</strong>] color is blue</p>
    
    <p>FALSE: What is your <strong>blah blah</strong> color? my [<strong>some favorite</strong>] color is blue</p>
  </blockquote>
  
  <p>The first two samples above are true because the word favorite is found outside of the [ ] symbols, whether it is inside them or not.</p>
  
  <p>The 3rd sample is false because even though there is the word favorite, it only appears inside the [ ] symbols - we should only check if it exists outside of the symbols.</p>
  
  <p>So I need a function to determine whether or not a word (favorite in this example) appears in a string, but ignoring the fact if the word is surrounded inside [ ] symbols.</p>