想求一个正则表达式
取得在2个变量(stra,strb)的字符串
str是从html文件里读出的
str="<table width=100% cellpadding=4 cellspacing=2><tr><td bgcolor=\"#D9F2FF\" width=20% align=right>国家:</td><td bgcolor=\"#F7F7F7\">中国</td></tr><tr><td bgcolor=\"#D9F2FF\" align=right>省份/州:</td><td bgcolor=\"#F7F7F7\">"
stra,strb是从数据库里读出
在这里如何取得'中国'这个字符串
string stra=Regex.Unescape(taskDistillData.Tables[TaskDistillData.TASKDISTILL_TABLE].Rows[j][TaskDistillData.DISTILLFIRST_FIELD].ToString());
string strb=Regex.Unescape(taskDistillData.Tables[TaskDistillData.TASKDISTILL_TABLE].Rows[j][TaskDistillData.DISTILLLAST_FIELD].ToString());
String pattern=strdistillfirst + ".*"+strdistilllast;
我是这样写的 不行 请大家帮我看看
取得在2个变量(stra,strb)的字符串
str是从html文件里读出的
str="<table width=100% cellpadding=4 cellspacing=2><tr><td bgcolor=\"#D9F2FF\" width=20% align=right>国家:</td><td bgcolor=\"#F7F7F7\">中国</td></tr><tr><td bgcolor=\"#D9F2FF\" align=right>省份/州:</td><td bgcolor=\"#F7F7F7\">"
stra,strb是从数据库里读出
在这里如何取得'中国'这个字符串
string stra=Regex.Unescape(taskDistillData.Tables[TaskDistillData.TASKDISTILL_TABLE].Rows[j][TaskDistillData.DISTILLFIRST_FIELD].ToString());
string strb=Regex.Unescape(taskDistillData.Tables[TaskDistillData.TASKDISTILL_TABLE].Rows[j][TaskDistillData.DISTILLLAST_FIELD].ToString());
String pattern=strdistillfirst + ".*"+strdistilllast;
我是这样写的 不行 请大家帮我看看
using System.Text.RegularExpressions;
public class StripHTMLTest{
public static void Main(){
string s=StripHTML("<HTML><HEAD><TITLE>中国石龙信息平台</TITLE></HEAD><BODY>faddfs龙信息平台</BODY></HTML>");
Console.WriteLine(s);
} public static string StripHTML(string strHtml){
string [] aryReg ={
@"<script[^>]*?>.*?</script>", @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>",
@"([\r\n])[\s]+",
@"&(quot|#34);",
@"&(amp|#38);",
@"&(lt|#60);",
@"&(gt|#62);",
@"&(nbsp|#160);",
@"&(iexcl|#161);",
@"&(cent|#162);",
@"&(pound|#163);",
@"&(copy|#169);",
@"&#(\d+);",
@"-->",
@"<!--.*\n"
}; string [] aryRep = {
"",
"",
"",
"\"",
"&",
"<",
">",
" ",
"\xa1",//chr(161),
"\xa2",//chr(162),
"\xa3",//chr(163),
"\xa9",//chr(169),
"",
"\r\n",
""
}; string newReg =aryReg[0];
string strOutput=strHtml;
for(int i = 0;i<aryReg.Length;i++){
Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase);
strOutput = regex.Replace(strOutput,aryRep[i]);
}
strOutput.Replace("<","");
strOutput.Replace(">","");
strOutput.Replace("\r\n","");
return strOutput;
}
}
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
for(Match m = regex.match(inputstr) ; m.Success ; m = m.NextMatch())
{
}你用Regulator这个工具写正则表达式比较方便。