title: Regular expression for removing whitespaces
body: <p>I have some text which looks like this - </p>
  
  <pre><code>"    tushar is a good      boy     "
  </code></pre>
  
  <p>Using javascript I want to remove all the extra white spaces in a string. </p>
  
  <p>The resultant string should have no multiple white spaces instead have only one. Moreover the starting and the end should not have any white spaces at all. So my final output should look like this - </p>
  
  <pre><code>"tushar is a good boy"
  </code></pre>
  
  <p>I am using the following code at the moment- </p>
  
  <pre><code>str.replace(/(\s\s\s*)/g, ' ')
  </code></pre>
  
  <p>This obviously fails because it doesn't take care of the white spaces in the beginning and end of the string.</p>