天天看點

正規表達式比對Flash

  public static string[] GetHtmlUrlList(string sHtmlText)

  {

  // 定義正規表達式用來比對 img 标簽

  Regex regImg = new Regex(@"]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[" "']?[\s\t\r\n]*(?[^\s\t\r\n""']*)[^]*?/?[\s\t \r\n]*>", RegexOptions.IgnoreCase);

  // 搜尋比對的字元串

  MatchCollection matches = regImg.Matches(sHtmlText);

  int i = 0;

  string[] sUrlList = new string[matches.Count];

  // 取得比對項清單

  foreach (Match match in matches)

  sUrlList[i++] = match.Groups["imgUrl"].Value;

  return sUrlList;

  }