asp正则表达式循环取TR中的数据

feishanm 2009-11-12 04:03:42
<table width="200" border="0">
<tr>
<td>张三</td>
<td>1112</td>
<td>SD001</td>
<td>123456</td>
</tr>
<tr >
<td >李四</td>
<td >1113</td>
<td >HY001</td>
<td >12547</td>
</tr>
<tr>
<td >test</td>
<td >54879</td>
<td >T0001</td>
<td >999985</td>
</tr>
</table>
有如上表格的HTML代码,通过正值表达式循环取TD中的内容,每个TR中的数据生成一条SQL语句
上面表格就生成三条SQL语句
如:insert into a values(张三,1112,SD001,123456)
insert into a values(李四,1113,HY001,12547)
谢谢!
...全文
184 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
rokey2009 2009-12-16
  • 打赏
  • 举报
回复
怎么看不了答案呢 我已经登录了
feishanm 2009-11-12
  • 打赏
  • 举报
回复
搞定了,结贴。
谢谢liuxiaoyi666
以后要多看看正则表达式的东西。
feishanm 2009-11-12
  • 打赏
  • 举报
回复
好的
^@^
  • 打赏
  • 举报
回复
这样的效果,应该没问题了...
  • 打赏
  • 举报
回复


patrn="<tr[^>]*>[^<]*<td[^>]*>([^<]*)<\/td>[^<]*<td[^>]*>([^<]*)<\/td>[^<]*<td[^>]*>([^>]*)<\/td>[^<]*<td[^>]*>([^>]*)<\/td>[^<]*</tr>"
str="<table width=""200"" border=""0""><tr><td>张三 </td><td>1112 </td><td>SD001 </td><td>123456 </td></tr></table>"
Set regEx = New RegExp ' 创建正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全程匹配。
Set Matches = regEx.Execute(str) ' 执行搜索。
alert(Matches.count)
For Each Match in Matches ' 循环遍历Matches集合。

' 张三出来了 Match.SubMatches(0)
Next

  • 打赏
  • 举报
回复
你小心点儿论坛里把我的代码多加了些空格
feishanm 2009-11-12
  • 打赏
  • 举报
回复
谢谢
我试试。
没玩过ASP的正则表达式,嘿嘿 。
  • 打赏
  • 举报
回复
再不会的话,我无语了...剩下的几个就是用Match.SubMatches(1) Match.SubMatches(2) Match.SubMatches(3)就得到了...
  • 打赏
  • 举报
回复
patrn="<tr[^>]*>[^<]*<td[^>]*>([^<]*)<\/td>[^<]*<td[^>]*>([^<]*)<\/td>[^<]*<td[^>]*>([^>]*)<\/td>[^<]*<td[^>]*>([^>]*)<\/td>[^<]*</tr>"
str="<table width=""200"" border=""0""><tr><td>张三 </td><td>1112 </td><td>SD001 </td><td>123456 </td></tr></table>"
Set regEx = New RegExp ' 创建正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分大小写。
regEx.Global = True ' 设置全程匹配。
Set Matches = regEx.Execute(str) ' 执行搜索。
alert(Matches.count)
For Each Match in Matches ' 循环遍历Matches集合。

' 张三出来了 Match.SubMatches(0)
Next
feishanm 2009-11-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 liuxiaoyi666 的回复:]
用子表达式的值取就成了
[/Quote]

大侠,能详细点吗?
谢谢
  • 打赏
  • 举报
回复
用子表达式的值取就成了
  • 打赏
  • 举报
回复
<tr[^>]*><td<tr[^>]*>([^>]*)<\/td><td<tr[^>]*>([^>]*)<\/td><td<tr[^>]*>([^>]*)<\/td><td<tr[^>]*>([^>]*)<\/td><td<tr[^>]*>([^>]*)<\/td></tr>

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧