title: Match "\b(OneTwoThree|OneTwo|TwoThree)\b" with least repetition
body: <p>I managed this with PCRE only, but I'd like it to work with Javascript's RegExp as well. That, and the regex is ugly. Are there any other, saner ways of accomplishing this?</p>
  
  <p><em>Note, that while the topic says "OneTwoThree", I'm using "qwe" for brevity.</em></p>
  
  <pre><code>$ cat test.txt | grep -oP '\b(q(\g&lt;we&gt;|\g&lt;w&gt;)|(?&lt;we&gt;(?&lt;w&gt;w)e))\b'
  qwe
  qw
  we
  </code></pre>
  
  <p>File test.txt contains:  </p>
  
  <p><code>qwe qw we q w e qq qe wq ww eq ew ee qqq qqw qqe qwq qww qeq qew qee wqq wqw wqe wwq www wwe weq wew wee eqq eqw eqe ewq eww ewe eeq eew eee</code></p>
  
  <p><em>(Only the first three should match.)</em></p>