title: Regex keyword matching
body: <p>I want to implement a regex matching function in javascript that matches one or more keywords in a text. Each keywords has to be found in any order. Keywords are entered by the user.</p>
  
  <p>Here's where i am at:</p>
  
  <pre><code>\b(smart.*\bwork.*|work.*\bsmart.*)
  </code></pre>
  
  <ul>
  <li>matches <code>"trying to work smarter"</code></li>
  <li>but not <code>"trying to work" or "trying to be smart"</code></li>
  </ul>
  
  <p>The problem with this approach is i have to create different ordered permutations (something like that anyway) of the keyword set.</p>
  
  <p>So the questions are:</p>
  
  <ol>
  <li>If there a simple RegEx-only way? (I.e <code>"\b(smart.*|work.*)&lt;magic:all,anyorder&gt;"</code> what will make sure all keywords are found, and in any order)</li>
  <li>If not - can you suggest a javascript implementation of array permutations (so that from <code>[1,2,3]</code> it generates <code>[[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]</code>)</li>
  </ol>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is intended to be used for searching a set of strings (10-50 strings) on the client side (in browser).</p>