62,046
社区成员
发帖
与我相关
我的任务
分享
string str = "<img src=xx.png />"
+ "<img src=\"aa.jpg\" />";
Regex reg = new Regex(@"(?is)<img[^>]*?scr=(['""\s]?)([^'""\s]+)\1[^>]*?>");
MatchCollection match = reg.Matches(str);
foreach (Match m in match)
{
Response.Write(m.Groups[2].Value + "<br/>");
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string str = "<img class=\"name\" src=\"123456\\789.jpg\" >";
Regex reg = new Regex(@"(?i)<img[^>]*?src=(['""]?)(?<src>[^'""\s>]*)\1[^>]*>");
MatchCollection mc = reg.Matches(str);
foreach (Match m in mc)
{
str = "\""+m.Groups["src"].Value+"\"";
}
Response.Write(str);
}
}
结果:"123456\789.jpg"