求一个正则表达式。要求是在 <SPAN class=question-title>我的电脑</SPAN>中提取出“我的电脑”这几个字 求一个正则表达式。要求是在 <SPAN class=question-title>我的电脑</SPAN>中提取出“我的电脑”这几个字 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string str = "<SPAN class=question-title>我的电脑</SPAN>";str = Regex.Replace(str,"<[^<>]+>","");Console.WriteLine(str); 不好意思,我的问题可能没描述太清楚。而我的需求是要在整个网页的HTML代码中只提取出question-title这个类标签中的文字,即这里的“我的电脑”。楼上的答案实际只是去掉了所有<>标签 string str = "<SPAN class=question-title>我的电脑</SPAN>"; Match m = Regex.Match(str, @"(?<=class=question-title[^>]*>)[^<]+"); Console.WriteLine(m); 正则替换replace\<[^<>]+\>为空即可 void Main(){ string s="<SPAN class=question-title>我的电脑</SPAN>"; foreach(Match m in Regex.Matches(s,@"(?is)<span[^>]*?class=(['""]?)question-title\1[^>]*>([^<]+)</span>")) { Console.WriteLine(m.Groups[2].Value); } //我的电脑} Regex reg = new Regex(@"(?is)<span\s=calss=""question-title""[^>]*>(.*?)</span>");MatchCollection mc = reg.Matches(str);foreach (Match m in mc){ TextBox2.Text += m.Groups[1].Value + "\n";} 分析历史数据获取信息 看得我晕.....休息.... c#调用c++DLL的动态链接库问题? C#窗体之间如何传值 【100分】(不够另贴加分) 如何在不知道事件处理方法的前提下,移除事件处理方法 第一次做这东西,请教一些关于画图,图形处理上面的问题,请各位大虾不吝赐教 如何用asp.net实现成批文件上传服务器 正则表达式replace的迷惑!!! 线程返回值问题 有人知道,怎么获得iis文件夹的地址吗?有没有系统函数可供调用??谢了 关于页面——如何做到这种效果 怎么读取节点中的值 谢谢
str = Regex.Replace(str,"<[^<>]+>","");
Console.WriteLine(str);
而我的需求是要在整个网页的HTML代码中只提取出question-title这个类标签中的文字,即这里的“我的电脑”。楼上的答案实际只是去掉了所有<>标签
Match m = Regex.Match(str, @"(?<=class=question-title[^>]*>)[^<]+");
Console.WriteLine(m);
void Main()
{
string s="<SPAN class=question-title>我的电脑</SPAN>";
foreach(Match m in Regex.Matches(s,@"(?is)<span[^>]*?class=(['""]?)question-title\1[^>]*>([^<]+)</span>"))
{
Console.WriteLine(m.Groups[2].Value);
}
//我的电脑}
MatchCollection mc = reg.Matches(str);
foreach (Match m in mc)
{
TextBox2.Text += m.Groups[1].Value + "\n";
}