title: Javascript regular expression: match anything up until something (if there it exists)
body: <p>I am new to regular expression and this may be a very easy question (hopefully).</p>
  <p>I am trying to use one solution for 3 kinds of string</p>
  <ul>
  <li>&quot;45%&quot;, expected result: &quot;45&quot;</li>
  <li>&quot;45&quot;, expected result: &quot;45&quot;</li>
  <li>&quot;&quot;, expected result: &quot;&quot;</li>
  </ul>
  <p>What I am trying (let the string be str):</p>
  <pre><code>str.match(/(.*)(?!%*)/i)[1]
  </code></pre>
  <p>This is in my head would sound like &quot;match any instance of anything up until '%' if it is found, or else just match anything&quot;</p>
  <p>In firebug's head, it seems to sound more like &quot;just match anything and completely disregard the negative lookahead&quot;. Also to make it lazy - <code>(.*)?</code> - doesn't seem to help.</p>
  <p>Let's forget for a second that in this specific situation I am only matching numbers, so a <code>/\d*/</code> would do. I am trying to understand a general rule so that I can apply it whenever.</p>
  <p>Anybody would be so kind to help me out?</p>