title: Replace specific words using regular expression (globally) - Java
body: <p>I am trying to come up with a regular expression to replace specific words irrespective of position / order but it doesn't seem to work</p>
  
  <p>Example input:</p>
  
  <pre><code>This is a a an the a the testing
  </code></pre>
  
  <p>regex:</p>
  
  <pre><code>(\sa\s)|(\san\s)|(\sthe\s)
  </code></pre>
  
  <p>Actual output:</p>
  
  <pre><code>This is a the the testing
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>This is testing
  </code></pre>