title: regex to match text between two closest words
body: <p>could you help me with regex to match text between two closest words, please?</p>
  
  <p>For example:  </p>
  
  <pre><code>text KEYWORD1 text KEYWORD1 text KEYWORD2 text KEYWORD2
  </code></pre>
  
  <p>The result must be:  </p>
  
  <pre><code>KEYWORD1 text KEYWORD2
  </code></pre>
  
  <p>This doesn't work, which is predictable:  </p>
  
  <pre><code>(KEYWORD1).*(KEYWORD2)
  </code></pre>
  
  <p>Is it even possible to accomplish this with regexp? If so, how it will work with finite state machine?<br>
  Java regexp syntax would be the best. Thank you in advance!</p>