title: What is the meaning of (/^\s+|\s+$/gm) in JavaScript?
body: <p>I came across this JavaScript function:</p>
  
  <pre><code>function myTrim(x) {
    return x.replace(/^\s+|\s+$/gm,'');
  }
  </code></pre>
  
  <p>I know that this function(<code>mytrim()</code>) replaces some characters in the string(x), but what does <code>/^\s+|\s+$/gm</code> do in the replace method?</p>
  
  <p>Where can I learn more about these things?</p>
  
  <p>Note- This function returns the string with removed spaces at both sides.</p>