62,266
社区成员
发帖
与我相关
我的任务
分享
string str="<img alt=\"\" src=\"/uploads/test.jpg\" width=\"701\" border=\"0\" />";
string result=string.Empty;
Regex reg=new Regex(@"<img [^>]*src=""(?<src>[^""]*)""[^>]*>");
MatchCollection m = reg.Matches(str);
for (int i = 0; i < m.Count; i++)
{
Response.Write(m[i].Groups["src"].ToString()+"<br>");
}
string str="<img alt=\"\" src=\"/uploads/test.jpg\" width=\"701\" border=\"0\" />";
string result=string.Empty;
Regex reg=new Regex(@"(?<=<img [^>]*src="")[^""]*(?=""[^>]*>)");
MatchCollection m = reg.Matches(str);
for (int i = 0; i < m.Count; i++)
{
Response.Write(m[i].Groups["src"].ToString()+"<br>");
}
string str="<img alt=\"\" src=\"/uploads/test.jpg\" width=\"701\" border=\"0\" />";
string result=string.Empty;
Regex reg=new Regex(@"(?<=<img [^>]*src="")[^""]*(?=""[^>]*>)");
result=reg.Match(str).Value;
string str="(?<=src[=]["])[^"]*(?=["])";
string str = "<img src=\"/uploads/test.jpg\" width=\"701\" border=\"0\" />"
System.Text.RegularExpressions.Regex reg=new System.Text.RegularExpressions.Regex(@"<img[^>].*?src=""(?<src>[^""].*)""[^>].*?>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.MatchCollection m = reg.Matches(str); //设定要查找的字符串
for (int i = 0; i < m.Count; i++)
{
Response.Write(m[i].Groups["src"].ToString()+"<br>");
}
string str = "<img src=\"/uploads/test.jpg\" width=\"701\" border=\"0\" />"
System.Text.RegularExpressions.Regex reg=new System.Text.RegularExpressions.Regex(@"<img[^>].*?src=""(?<src>[^""].*)""[^>].*?>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.MatchCollection m = reg.Matches(NewsContents); //设定要查找的字符串
for (int i = 0; i < m.Count; i++)
{
Response.Write(m[i].Groups["src"].ToString()+"<br>");
}
//注意名字名间: using System.Text.RegularExpressions;
public string ImageSrc(string InputText)
{
Match m = Regex.Match(InputText, "(?<=<img.+?src=\")[^\"]+(?=\")", RegexOptions.IgnoreCase);
string src = m.Value;
m = Regex.Match(InputText, "<img.+?\\/?>", RegexOptions.IgnoreCase);
return m.Value;
}