title: JavaScript RegEx - Minimum characters with Wildcard
body: <p>I'm working on matching a wildcard search input. it's a name field.
  Below are the conditions I need to match.</p>
  
  <ol>
  <li>User must enter at least 3 alphanumeric characters, if he chooses to do a Wildcard search</li>
  <li>User may/maynot enter a wildcard at the start or end of the string,but it  can be on either side.</li>
  <li>Allow spaces between words.</li>
  </ol>
  
  <p>I want to mention that i'm trimming the string before doing a match. This is what I tried so far.</p>
  
  <pre><code>^[^\W_](\s?\w?)*$|^[^\W_]{3,}(\s?\w?)*\*$|^[\*][^\W_]{3,}(\s?\w?)*$
  </code></pre>
  
  <p><img src="https://www.debuggex.com/i/z-zaJ26ribGZ27xJ.png" alt="Regular expression visualization"></p>
  
  <p><a href="https://www.debuggex.com/r/z-zaJ26ribGZ27xJ" rel="nofollow">Debuggex Demo</a></p>
  
  <p>Below are some examples I tried -</p>
  
  <ul>
  <li><em>someone xxx, someone xxx yyy</em> - Passed</li>
  <li>someone* xxx- Failed</li>
  <li><em>someone , someone</em> - Passed</li>
  </ul>
  
  <p>This is the nearest match of what i want- But it fail for these test case.</p>
  
  <ul>
  <li><p>AB asf* -- Fails , this will pass- ABC asf*</p></li>
  <li><p>*AB asf -- Fails , this will pass- *ABC asf</p></li>
  </ul>
  
  <p>I know I have a condition that says - starts with at least 3 alphanumeric character and repeat space and alphanumeric characters.</p>
  
  <p>That's where I need help with.</p>
  
  <p>Thanks.</p>