62,041
社区成员
发帖
与我相关
我的任务
分享
string str="<html>asfsad<META content=\".net,正则表达式,使用,反向引用\" name=\"Keywords\" /> asfasfas<META name=\"Keywords\" content=\"测试第二种情况\" />";
System.Text.RegularExpressions.Regex reg=new System.Text.RegularExpressions.Regex(@"<meta(\s+content=(['""]?)(?<content>[^""'>]*)(\2)\s+name=(['""]?)Keywords(\4)\s+)|(\s+name=(['""]?)Keywords(['""]?)\s+content=(['""]?)(?<content>[^""'>]*)(['""]?)\s+).*?>",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["content"].ToString()+"<br>");
}
System.Text.RegularExpressions.Regex reg=new System.Text.RegularExpressions.Regex(@"<meta\s+.*?content=(['""]?)(?<content>[^""'>]*)(\1)\s+name=(['""]?)Keywords(\3)\s.*?>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
string str="<META content=\".net,正则表达式,使用,反向引用\" name=\"Keywords\" /> ";
System.Text.RegularExpressions.Regex reg=new System.Text.RegularExpressions.Regex(@"<meta\s+.*?content=(['""]?)(?<content>[^""'>]*)(\1)\s+.*?>",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["content"].ToString()+"<br>");
}
string text = "<html>asfasfas<META name=\"Keywordsd\" content=\"测试第二种情况\" />";
text = Regex.Match(text, @"(?<=meta.+?(?<name>name=""Keywords"".+?)*content=['""]?)[^""']+(?=[""'](?(name)|.+name=""Keywords""))", RegexOptions.IgnoreCase).Value;