title: RegEx to extract parameters from url hash in JavaScript
body: <p>My urls will look like:</p>
  
  <pre><code>http://example.com/whatever#page?x=1&amp;locale=hu&amp;y=2
  http://example.com/whatever#page?x=1&amp;locale=hu
  http://example.com/whatever#page?locale=hu
  http://example.com/whatever#page?locale=
  http://example.com/whatever#page?x=1
  http://example.com/whatever#page
  http://example.com/whatever
  </code></pre>
  
  <p>I'd like to get the locale parameter or empty string if it's not set.</p>
  
  <p>I'm trying something like:</p>
  
  <pre><code>locale = location.hash.replace(/.*(?:[?&amp;]locale=([^&amp;]*))?.*/, "$2");
  </code></pre>
  
  <p>But my problem is that I couldn't find the right RegExp that works for all cases (both when there's locale= in the hash and when there isn't)</p>