<table>
<tr>
<td valign=center align=middle width=87 bgcolor=#CBF1FC height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana"><script language="JavaScript">tranCode("840")</script></span></div>
</td>
<td valign=center align=right width=79 height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">6.7674</span></div>
</td>
<td valign=center align=right width=79 height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">6.7946</span></div>
</td>
<td valign=center align=right width=79 height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">6.7132</span></div>
</td>
<td valign=center align=right width=79 height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">6.7946</span></div>
</td> </tr></table>
我从一个网站上获取的信息,下面是获取信息的一行,我要提取每一行中每一列的数据
6.7674 6.7946 6.7946 6.7132
用正则表达式怎么提取,请指点一下,谢谢!
<tr>
<td valign=center align=middle width=87 bgcolor=#CBF1FC height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana"><script language="JavaScript">tranCode("840")</script></span></div>
</td>
<td valign=center align=right width=79 height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">6.7674</span></div>
</td>
<td valign=center align=right width=79 height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">6.7946</span></div>
</td>
<td valign=center align=right width=79 height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">6.7132</span></div>
</td>
<td valign=center align=right width=79 height=20>
<div align="center"><span
style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">6.7946</span></div>
</td> </tr></table>
我从一个网站上获取的信息,下面是获取信息的一行,我要提取每一行中每一列的数据
6.7674 6.7946 6.7946 6.7132
用正则表达式怎么提取,请指点一下,谢谢!
may it be
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.
Regex(@"<script[\s\s]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex
(@" href *= *[\s\s]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex
(@" on[\s\s]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex
(@"<iframe[\s\s]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex
(@"<frameset[\s\s]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex
(@"<\/*[^<>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
// html = regex1.Replace(html, ""); //过滤<script></script>标记
// html = regex2.Replace(html, ""); //过滤href=javascript: (<a>) 属性
// html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
// html = regex4.Replace(html, ""); //过滤iframe
// html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤html
//html通用标签:"/<(?:(?:\/?[A-Za-z]\w+\b(?:[=\s](['"]?)[\s\S]*?\1)*)|(?:!--[\s\S]*?--))>/g"
return html;
}
<head runat="server">
<title>无标题页</title> <script src="App_common/scripts/jquery-1.4.2.min.js" type="text/javascript"></script> <script type="text/javascript">
$(function(){
var Htmls=$("table").find("span");
var temp="";
$(Htmls).each(function(entrtyIndex,entrty){
if(Htmls.eq(parseInt(entrtyIndex)).html()!="")
temp+=Htmls.eq(parseInt(entrtyIndex)).html()+",";
})
alert(temp);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td valign="center" align="middle" width="87" bgcolor="#CBF1FC" height="20">
<div align="center">
<span style="font-size: 9pt; font-family: 宋体, Verdana">
</span>
</div>
</td>
<td valign="center" align="right" width="79" height="20">
<div align="center">
<span style="font-size: 9pt; font-family: 宋体, Verdana">6.7674</span></div>
</td>
<td valign="center" align="right" width="79" height="20">
<div align="center">
<span style="font-size: 9pt; font-family: 宋体, Verdana">6.7946</span></div>
</td>
<td valign="center" align="right" width="79" height="20">
<div align="center">
<span style="font-size: 9pt; font-family: 宋体, Verdana">6.7132</span></div>
</td>
<td valign="center" align="right" width="79" height="20">
<div align="center">
<span style="font-size: 9pt; font-family: 宋体, Verdana">6.7946</span></div>
</td>
</tr>
</table>
</form>
</body>
</html>
加个
<input type="hidden" raunt="server" id="hdTemp">js$("hdTemp").val(temp);cs后台:this.hdTemp.vaule;//再做字符串操作,不就一样么
string regStr = "<span\\s+style=\"FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana\">\\s*([\\d\\.]*)\\s*</span>";
MatchCollection matches = Regex.Matches(content, regStr, RegexOptions.Multiline);
foreach (Match mc in matches)
{
//按你的原文,这里应依次得到4个mc
int yourData=int.Parse(mc.Groups[1].Value);
}
double yourData=double.Parse(mc.Groups[1].Value);
MatchCollection mc = Regex.Matches(html,@"(?is)"><span\s+style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体, Verdana">(?<value>\d+(.\d+)?)</span>");
foreach(Match m in mc)
{
//m.Groups["value"].Value;
}