62,074
社区成员
发帖
与我相关
我的任务
分享
<img alt="" src="/WebUI/Background/images/BG-header.jpg" style="width:150px;height:120px; " />
string str = "<img alt=\"\" src=\"/WebUI/Background/images/BG-header.jpg\" style=\"width:150px;height:120px; \" />";
Regex reg = new Regex(@"(?i)<img[^>]*?src=(['""]?).*/((?:(?!\1).)*?)\1[^>]*?>");
Response.Write(reg.Match(str).Groups[2].Value);
//BG-header.jpg
public string Image(string str)
{
string result = "";
Regex re = new Regex("(?<=src=\\\").*?(?=\\\")", RegexOptions.None);
MatchCollection mc = re.Matches(str);
foreach (Match ma in mc)
{
result += ma.Value + ",";
if (result.Length > 0)
{
break;
}
}
return result.TrimEnd(',');
}
string str = "<img alt=\"\" src=\"/WebUI/Background/images/BG-header.jpg\" style=\"width:150px;height:120px; \" />";
Regex re = new Regex("(?<=src=\\\").*?(?=\\\")", RegexOptions.None);
str = re.Match(str).Value.Substring(re.Match(str).Value.LastIndexOf('/') + 1);
//结果:BG-header.jpg