日期:2014-05-19  浏览次数:20997 次

也求一个正则表达式
在一个多行文本里包括 <span   id= "DataGrid1__ctl3_Label6 "> 2007-1-1 </span>

想把2007-1-1这几个提取出来

比较急,本来想自己研究的,时间不允许...麻烦大家了




------解决方案--------------------
string strSrc =
"在一个多行文本里包括 <span id=\ "DataGrid1__ctl3_Label6\ "> 2007-1-1 </span> ";
Match res = Regex.Match(strSrc, "(? <= <span[^> ]+?> )[^ <]+?(?= </span> ) ");
if (res.Success)
{
MessageBox.Show(res.Value);
}
------解决方案--------------------
对wuyazhe的稍作改进
"(? <= <span id=\ "DataGrid1__ctl3_Label6\ "> )[^ <]+?(?= </span> ) "
------解决方案--------------------
我也来掺和一下-_-#

提取一个还是多个,另外id= "DataGrid1__ctl3_Label6 "这里固不固定,如果不固定,以什么为标志定位到你的要数据, <span..> 和 </span> 就可以了吗

这是id= "DataGrid1__ctl3_Label6 "固定的
MatchCollection mc = Regex.Matches(yourStr, @ " <span\s+id= " "DataGrid1__ctl3_Label6 " "> (? <content> [\s\S]*?) </span> ", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[ "content "].Value + "\n ";
}

这是以 <span来取的
MatchCollection mc = Regex.Matches(yourStr, @ " <span[^> ]*> (? <content> [\s\S]*?) </span> ", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[ "content "].Value + "\n ";
}