title: Regex to match words in a sentence by its prefix
body: <p>I have this regex on mongodb query to match words by prefix:</p>
  
  <pre><code>{sentence: new RegExp('^'+key,'gi')}
  </code></pre>
  
  <p>What would be the right regex pattern if I want it to match a sentence that has at least a word starting with <code>key</code> prefix? For example:</p>
  
  <p>If I have a sentence </p>
  
  <blockquote>
    <p>"This is a dog"</p>
  </blockquote>
  
  <p>when <code>key</code> is 'do', then it should match that sentence since prefix 'do' is a substring of 'dog'.</p>
  
  <p>My solution as of now only works for the first word of the sentence. It so far only matches that sentence if I type in 't' or 'th' or 'this'. It wouldnt match that sentence whenever I type in 'i' (prefix for 'is') or 'do' (prefix for 'dog').  </p>