帮忙写两个C#的正则表达式,取body间的代码 和 form间的代码?取<body bgcolor .....><table>.....</table></body>间的代码。
注意:不要body标签,body不区分大小写,body,BODY,bOBy一视同仁。body的属性有可能 双引号,单引号都有取<form id="form1" name='sss' .....><table>.....</table></form>间的代码。
注意:不要form标签,form不区分大小写,form,FORM,fORm一视同仁。form的属性有可能 双引号,单引号都有。另外一个页面有多个form,可根据from的ID来取那个form间的代码。
劳驾各位!!!!
注意:不要body标签,body不区分大小写,body,BODY,bOBy一视同仁。body的属性有可能 双引号,单引号都有取<form id="form1" name='sss' .....><table>.....</table></form>间的代码。
注意:不要form标签,form不区分大小写,form,FORM,fORm一视同仁。form的属性有可能 双引号,单引号都有。另外一个页面有多个form,可根据from的ID来取那个form间的代码。
劳驾各位!!!!
Regex reg=new Regex("(?is)<body[^>]*>(?<body>.*?)</body>");
string result=reg.Match("你的网页代码").Groups["body"].Value;2、
Regex reg=new Regex("(?is)<form id=(['\"])[^'\"]*\1[^>]*>(?<form>.*?)</form>");//可以把正则表达式中的[^'\"]*换成你的真实id,比如form1
string result=string.Empty;
foreach(Match m in reg.Matches("你的网页代码"))
{
result+=m.Groups["form"].Value+"\r\n";
}
dd.Append(@"<html><head></head><from id=""f3""></form><body bgcolor='#ffffff'>s《》<from id=""f2""></form><br> <table><from id=""f1""></form></table>e</Body></html>"); //Regex reg = new Regex("(?is)<body[^>]*>(?<body>.*?)</body>");
//string result = reg.Match(dd.ToString()).Groups["body"].Value; //Regex reg = new Regex("(?is)<form id=(['\"])[^'\"]*\\1[^>]*>(?<form>.*?)</form>");//可以把正则表达式中的[^'\"]*换成你的真实id,比如form1
Regex reg = new Regex("(?is)<form id=(['\"])f2\\1[^>]*>(?<form>.*?)</form>");//可以把正则表达式中的[^'\"]*换成你的真实id,比如form1
string result = string.Empty;
foreach (Match m in reg.Matches(dd.ToString()))
{
result += m.Groups["form"].Value + "\r\n";
} this.Label1.Text = result;
没有测试成功
Match mc = reg.Match(content);
if (mc.Success)
{
return mc.Groups[0].Value.Trim();
}