日期:2014-05-17 浏览次数:20493 次
string URL = "<img[^>]*src=(\"|')(?<src>[^(\"|')]*)(\"|')[^>]*>"; MatchCollection MC = new Regex(URL, RegexOptions.IgnoreCase).Matches(strHTML); List<string> arrOutPut = new List<string>(); foreach (Match m in MC) { arrOutPut.Add(m.Groups["src"].Value); }
------解决方案--------------------
string str = "<img [这里面的内容不确定] src=\"a.gif\"> ";
str = Regex.Replace(str, @"(?is)(<img((?!src=)[^>])*src=['""])([^'""]+)(['""][^>]*>)", "$1img/$3$4");
------解决方案--------------------
string content = @"<img [这里面的内容不确定] src=""a.gif""> "; Regex reg = new Regex(@"(?is)(<img[^>]+src="")([^""]+)("")"); Match m = reg.Match(content); content = reg.Replace(content, "$1image/$2$3"); MessageBox.Show(content);