title: How to selectively remove line breaks from URLs
body: <p>On a messaging system, line breaks have been added automatically when messages are posted after a certain number of characters (silly way to do things but unfortunately that isn't allowed to be changed). This means that breaks have been automatically inserted into URLs, so that long ones are split up, eg:</p>
  
  <p><code>http://www.stackoverflow.com/some-more-&lt;br/&gt;stuff</code></p>
  
  <p>When messages are retrieved, a function converts links into tags, which for this URL results in:</p>
  
  <pre><code>&lt;a href='http//www.stackoverflow.com/some-more-'&gt;http://www.stackoverflow.com/some-more-&lt;/a&gt;stuff
  </code></pre>
  
  <p>I need to remove the <code>&lt;br/&gt;</code> before it's turned into a link.</p>
  
  <p>I have had the message split into words on spaces, then iterated through each word, seeing if it contains 'http://' or 'www.' and then replacing <code>&lt;br/&gt;</code> with an empty string if it does.</p>
  
  <p>However, this only works on URLs entered in a paragraph, for example:</p>
  
  <blockquote>
    <p>The URL is <a href="http://www.stackoverflow.com">http://www.stackoverflow.com</a></p>
  </blockquote>
  
  <p>It doesn't work for URLs entered with line breaks around it, for example:</p>
  
  <blockquote>
    <p>Here's the URL:</p>
    
    <p><a href="http://www.stackoverflow.com">http://www.stackoverflow.com</a></p>
    
    <p>And here's some more text</p>
  </blockquote>
  
  <p>..is chopped into:</p>
  
  <blockquote>
    <p>Here's the URL:http://www.stackoverflow.comAnd here's some more text</p>
  </blockquote>
  
  <p>..because all the line breaks have been removed in this 'word' (as I'm splitting on spaces, all of that is seen as one word).</p>
  
  <p>I thought I could split on line breaks, but then this won't work for URLs entered in a paragraph as in the first example, and it will also split in the middle of any URLs that contain a break.</p>
  
  <p>Clearly I need to somehow just find URLs and replace line breaks inside them, but I'm having real trouble with this, as I just can't seem to do it!</p>
  
  <p>If I've left out any details feel free to ask and I'll get back at once. Thanks :)</p>
  
  <p>PS - This is being coded in C#.</p>