title: Regular expression - val.replace(/^[^a-zA-Z0-9]*|[^a-zA-Z0-9]*$/g,"'');
body: <p>I was learning regular expression, It seems very much confusing to me for now. </p>
  
  <pre><code>val.replace(/^[^a-zA-Z0-9]*|[^a-zA-Z0-9]*$/g, '');
  </code></pre>
  
  <p>In the above expression </p>
  
  <p>1) which part denotes not to include white space? as i am trying to exclude all non alphanumeric characters.</p>
  
  <p>2) Since i don't want to use even '$' and '<em>'(underscore) can i specify '$' &amp; '</em>'(underscore) in expression something like below?     </p>
  
  <pre><code>val.replace(/^[^a-zA-Z0-9$_]*|[^a-zA-Z0-9$_]*/g, '');?
  </code></pre>
  
  <p>3) As '<code>x|y</code>' specify that - "Find any of the alternatives specified". Then Why we have used something like this <code>[^a-zA-Z0-9]|[^a-zA-Z0-9]</code> which is same on both sides?</p>
  
  <p>Please help me understand this, Finding it bit confused and difficult.</p>