title: Replace all spaces except the ones with in HTML tags
body: <p>I need to replace all spaces with html code, i.e. &amp;nbsp, in a string. Currently following, does the replacement but it also replaces the spaces with in html tags like <code>&lt;a href="http://google.com" /&gt;</code>.</p>
  
  <pre><code>string.replaceAll(" ", "&amp;nbsp")
  </code></pre>
  
  <p>But I need it to not change the tags.</p>
  
  <p>Example:</p>
  
  <pre><code>String s1 = "Hello!, Check out this &lt;^a href=\"http://www.entrepreneur.com/article/234538\"&gt;10 Movies Every Entrepreneur Needs to Watch &lt;^/a&gt;"
  </code></pre>
  
  <p>After replacment, it should be like;</p>
  
  <pre><code>String s1 = "Hello!,&amp;nbspCheck&amp;nbspout&amp;nbspthis&amp;nbsp&lt;^a href=\"http://www.entrepreneur.com/article/234538\"&gt;10&amp;nbspMovies&amp;nbspEvery&amp;nbspEntrepreneur&amp;nbspNeeds&amp;nbspto&amp;nbspWatch&amp;nbsp&lt;^/a&gt;"
  </code></pre>
  
  <p>Can anybody suggest a more intelligent regex to accomplish the task?</p>