title: Regex Expression for a URL Whitelist
body: <p>This has been driving me crazy.</p>
  
  <p>I need to construct a single regex expression of a whitelist of urls to allow my site to link to.
  They should be of the form:</p>
  
  <pre><code>*.microsoft.com/*
  </code></pre>
  
  <p>So the following urls are valid:</p>
  
  <pre><code>http://digital.microsoft.com/audio/somefile.wmv
  http://sharepoint.microsoft.com/pages/p1
  </code></pre>
  
  <p>And the following invalid:</p>
  
  <pre><code>http://badsite.microsoft.com.me
  http://www.microsoft.com.me/runthis
  </code></pre>
  
  <p>I need a regex expression which will allow valid microsoft sites to be linked to, but block malicious sites which my submit links with the words microsoft.com in them. </p>
  
  <p>Any help is appreciated!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Based on the answer by @ruakh, I was able to tweak the expression to match my scenario:
  I will mark his post as the answer.</p>
  
  <p>Expression: <code>^([a-z|A-Z])+?://([^/]+[.])?(microsoft[.]com|MICROSOFT[.]COM)?(/.*)?$</code></p>
  
  <p>This expression correctly matches the following:</p>
  
  <ul>
  <li><code>http://test.microsoft.com/?page=1</code> <code>http://msevents.microsoft.com</code></li>
  <li><code>https://myevents.microsoft.com/somesubsite/Event.aspx?EventID=56456&amp;Culture=en-US</code></li>
  <li><code>mms://digital.microsoft.com/456/videos/23800_str.wmv</code></li>
  <li><code>http://go.microsoft.com/?linkid=9775098</code></li>
  <li><code>http://GO.MICROSOFT.COM/?linkid=9775098</code></li>
  </ul>
  
  <p>And correctly does not match the following:</p>
  
  <ul>
  <li><code>http://me.microsoft.com.au</code></li>
  <li><code>http://microsoft.com.mysite.com</code></li>
  <li><code>http://microsoft.com.mysite.com/blah</code></li>
  <li><code>mms://microsoft.com.mysite.com</code></li>
  </ul>