title: Regular Expressions To Extract All Images And HTML
body: <p>I'm trying to figure out the regular expressions for the following and can't seem to get it right.  Can someone advise me?</p>
  
  <p>In a nutshell I have an htmlString which is:</p>
  
  <pre><code>        htmlString = "&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Here are some images.&lt;/br&gt;1) &lt;IMG style='MARGIN-BOTTOM: 20px; MARGIN-LEFT: 20px' align=right src='images/sample001.jpg'&gt;2) &lt;IMG style='MARGIN-BOTTOM: 25px; MARGIN-LEFT: 25px' align=right src='images/sample002.png'&gt;&lt;/br&gt; And some docs as well.&lt;/br&gt;1) href='javascript:parent.POPUP({url:'testDoc001.htm',type:'shared',width:600,height:645})'&gt;&lt;/br&gt;2) href='javascript:parent.POPUP({url:'testDoc002.html',type:'shared',width:700,height:712})'&gt;&lt;/br&gt;&lt;/BODY&gt;&lt;/HTML&gt;";
  </code></pre>
  
  <p>I run this through the following routine in C#, WPF:</p>
  
  <hr>
  
  <pre><code>    private static List&lt;string&gt; ExtractData(string htmlString)
      {
          List&lt;string&gt; data = new List&lt;string&gt;();
  
          //***  Get The Images ***
          string pattern = @"&lt;img .* src='(.+\.(jpg|bmp|png))'";
  
          Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
          MatchCollection matches = rgx.Matches(htmlString);
  
          for (int i = 0, l = matches.Count; i &lt; l; i++)
          {
              data.Add(matches[i].Value);
          }
  
          //***  Get Html Pages ***
          pattern = @"url:'([^']*)'";
  
          rgx = new Regex(pattern, RegexOptions.IgnoreCase);
          matches = rgx.Matches(htmlString);
  
          for (int i = 0, l = matches.Count; i &lt; l; i++)
          {
              data.Add(matches[i].Value);
          }
  
          return data;
      }--------------------------------------------------------------------------------------
  </code></pre>
  
  <p>and the result I get is:</p>
  
  <p>[0] = "&lt; IMG style='MARGIN-BOTTOM: 20px; MARGIN-LEFT: 20px' align=right src='images/sample001.jpg'>2) &lt; IMG style='MARGIN-BOTTOM: 25px; MARGIN-LEFT: 25px' align=right src='images/sample002.png'"</p>
  
  <p>[1] = "url:'testDoc001.htm'" </p>
  
  <p>[2] = "url:'testDoc002.html'"</p>
  
  <p>What I really want is:</p>
  
  <p>[0] = "images/sample001.jpg"</p>
  
  <p>[1] = "images/sample002.png"</p>
  
  <p>[2] = "testDoc001.htm"</p>
  
  <p>[3] = "testDoc002.html"</p>
  
  <p>Can someone tell me what I'm doing wrong in my Regular Expression?</p>
  
  <p>Thanks</p>