Posted By

leonbda on 01/21/09


Tagged

path array RegularExpression photo


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

umang_nine
vali29
khouser


Parse html via RegularExpression and place results in Array


 / Published in: C#
 

In this case I'm looking for image sources in html and placing them in array.

  1. using System.Text.RegularExpressions;
  2.  
  3. //looking for photo paths with REGX-a
  4. string nl = // in this case page html.
  5. MatchCollection mc = null;
  6. string sRegExp = "src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?";
  7. mc = Regex.Matches(nl, sRegExp);
  8.  
  9. string[] path;
  10. for (int j = 0; j < mc.Count; j++)
  11. {
  12. path = mc[j].Value.Split('"');
  13. Response.Write(path[1].ToString().Trim() + "<br />");
  14. }

Report this snippet  

You need to login to post a comment.