正则表达式,急! 如何取得<form action="lc.asp" method="post"><BR><BR><BR>正文<BR><BR></form>之间"正文"的内容啊?还请高手指教. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 补充:真正的字符串里有若干个<form>标记,但action内容不同. string a="<form action=\"lc.asp\" method=\"post\"><BR><BR><BR>正文<BR><BR></form>";Regex reg=new Regex("(?<=<BR>)[^<]+(?=<BR>)");a=reg.Match(a).Value; TO:cancerser(都是混饭吃,记得要结帖) 我今天早上才開始接觸正則。你給的例子可以,但用到我的實例中不行!我的實例內容大概如下:.....<form action="login.asp" method="post"><BR><BR>登录<BR><BR></form><form action="lc.asp" method="post"><BR><BR><BR> <font color='red'>北京至广州</font> <font color='red'>2575</font>公里<BR><BR><BR></form>.....我想取出這一段:<font color='red'>北京至广州</font> <font color='red'>2575</font>公里有個問題:假設我想取“a”到"b"之間的內容,正則如何表達呢???謝謝! ArrayList results = new ArrayList();string str = "<form action=\"lc.asp\" method=\"post\"><BR><BR><BR>正文<BR><BR></form>";string pattern1 = @"\<form action=[^<>]*\>(.*)\<\/form\>";string pattern2 = @"\<[^\<\>]*\>"; //这部分是你要删除的部分,可以改为“\<BR\>”或其它int pos = 1;Regex re1 = new Regex(pattern1, RegexOptions.Singleline);Regex re2 = new Regex(pattern2, RegexOptions.Singleline);MatchCollection mc = re1.Matches(str);IEnumerator ie = mc.GetEnumerator();while (ie.MoveNext()){ Match m = ie.Current as Math; results.Add(re2.Replace(m.Groups[pos].Value, ""));}return results; (?<=<BR>)[^<]+(?=<BR>)//和我这种写法类似(?<=a).*(?=b) 这样就是取ab之间的东西至于你这个 我建议这么写string a=yourString;Regex reg=new Regex("(?<=<form[^>]*>).+(?=</form>)",RegexOptions.Singleline|RegexOptions.IgnoreCase);foreach(Match m in reg.Matches(a)){ a=Regex.Replace(m.Value,"<BR>","",RegexOptions.IgnoreCase);}//这是个循环,好好看看这里面的a的值 去掉所有HTML语言,便可以正文内容!str = "<form action="lc.asp" method="post"><BR><BR><BR>正文<BR><BR></form>";str = Regex.Replace(str, @"<[^<]*>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);ok! 客户端文件下载 onchange 事件 不响应中文输入 Visual Web Developer 2005 速成版的测试版 2的问题 Repeater中绑定控件的问题 请高手帮帮忙!!谢谢!新手问题!!! 一个关于新浪的技术问题 能自定义alert 的大小吗?? 周五我妈过生日,向大家索取一点祝福 如何在两个页面之间传递数据集??? icery、各位面向对象高手进来看一看。为什么我想自定义控件及template出错 XSLT processing failed csdn网站问题 一个奇怪的存储过程问题!
Regex reg=new Regex("(?<=<BR>)[^<]+(?=<BR>)");
a=reg.Match(a).Value;
你給的例子可以,但用到我的實例中不行!
我的實例內容大概如下:
.....
<form action="login.asp" method="post">
<BR><BR>登录<BR><BR>
</form>
<form action="lc.asp" method="post">
<BR><BR><BR>
<font color='red'>北京至广州</font> <font color='red'>2575</font>公里<BR><BR><BR>
</form>
.....
我想取出這一段:<font color='red'>北京至广州</font> <font color='red'>2575</font>公里有個問題:
假設我想取“a”到"b"之間的內容,正則如何表達呢???
謝謝!
string str = "<form action=\"lc.asp\" method=\"post\"><BR><BR><BR>正文<BR><BR></form>";
string pattern1 = @"\<form action=[^<>]*\>(.*)\<\/form\>";
string pattern2 = @"\<[^\<\>]*\>"; //这部分是你要删除的部分,可以改为“\<BR\>”或其它
int pos = 1;Regex re1 = new Regex(pattern1, RegexOptions.Singleline);
Regex re2 = new Regex(pattern2, RegexOptions.Singleline);MatchCollection mc = re1.Matches(str);
IEnumerator ie = mc.GetEnumerator();
while (ie.MoveNext())
{
Match m = ie.Current as Math;
results.Add(re2.Replace(m.Groups[pos].Value, ""));
}return results;
//和我这种写法类似
(?<=a).*(?=b) 这样就是取ab之间的东西
至于你这个 我建议这么写
string a=yourString;
Regex reg=new Regex("(?<=<form[^>]*>).+(?=</form>)",RegexOptions.Singleline|RegexOptions.IgnoreCase);
foreach(Match m in reg.Matches(a))
{
a=Regex.Replace(m.Value,"<BR>","",RegexOptions.IgnoreCase);
}//这是个循环,好好看看这里面的a的值
str = Regex.Replace(str, @"<[^<]*>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);ok!