title: How to trim all non-alphanumeric characters from start and end of a string in Javascript?
body: <p>I have some strings that I want to clean up by removing all non-alphanumeric characters from the beginning and end.</p>
  
  <p>It should work on these strings:</p>
  
  <pre><code>)&amp;*@^#*^#&amp;^%$text-is.clean,--^2*%#**)(#&amp;^ ---&gt;&gt; text-is.clean,--^2
  
  -+~!@#$%,.-"^&amp;example-text@is.clean,--^#*%#**)(#&amp;^ ---&gt;&gt; example-text@is.clean
  </code></pre>
  
  <p>I have this regex, which removes them from the whole string:</p>
  
  <pre><code>val.replace(/[^a-zA-Z0-9]/g,'')
  </code></pre>
  
  <p>How would I change it to only remove from the beginning and end of string?</p>