◆求正则表达式的写法?忘高手赐教
网页代码如下:要将所有匹配的checkbox控件全部找出,并将所有的名字匹配<TD height=30><DIV class=STYLE19 align=center><INPUT type=checkbox value=1
name=checkbox> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=2
name=checkbox2> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=3
name=checkbox3> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=4
name=checkbox4> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=5
name=checkbox5> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=6
name=checkbox6> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=7
name=checkbox7> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=8
name=checkbox8> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=9
name=checkbox9> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=10
name=checkbox10> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=11
name=checkbox11> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=12
name=checkbox12> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=13
name=checkbox13> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=14
name=checkbox14> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=15
name=checkbox15> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=16
name=checkbox16> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=17
name=checkbox17> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=18
name=checkbox18> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=19
name=checkbox1949> </DIV></TD>
</TR>
<TR>
<TD height=30>
<DIV class=STYLE19 align=center><INPUT type=checkbox value=20
name=checkbox20> </DIV></TD>这样写提示错误: Local $nOffset = 1
Local $array
$array = StringRegExp($sHTML, 'checkbox\w*', 1, $nOffset)
For $i = 0 To UBound($array) - 1
MsgBox(0, "正则测试 标志值 1 - " & $i, $array[$i])
Next checkbox\d+ 我的意思是返回:checkbox
checkbox2
checkbox3
checkbox4
.......
checkbox20 本帖最后由 afan 于 2011-10-18 23:37 编辑
(checkbox\d*)>标志3 谢谢“afan”老大,我把我程序源码发上来,您帮忙看看,我怎么只获取了一个“checkbox”呢?#include <Date.au3>
#include <IE.au3>
#include <Excel.au3>
#include "WinHttp.au3"
#include <File.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>
#include <Array.au3>
Dim $i = 0
$oIE = _IECreate("http://www.wdxc.gov.cn/vote/vote1.asp")
Sleep(1000)
$sHTML = _IEBodyReadHTML($oIE)
Local $nOffset = 1
Local $array
Local $file = FileOpen("test.txt", 1)
; 检查打开的文件可写
If $file = -1 Then
MsgBox(0, "错误", "不能打开文件.")
Exit
EndIf
FileWrite($file, $sHTML)
FileClose($file)
$array = StringRegExp($sHTML, '(checkbox\d*)>', 1)
For $i = 0 To UBound($array) - 1
MsgBox(0, "正则测试 标志值 1 - " & $i, $array[$i])
Next
本帖最后由 tsui 于 2011-10-19 07:34 编辑
标志3,后面>还要处理 第31行改成:$array = StringRegExp($sHTML, '(checkbox\d*)>', 3) 试试呢! 回复 5# sdwd_lhq
不是说了标志是3吗,不是1,1只会获取1组~$array = StringRegExp($sHTML, '(checkbox\d*)>', 3)
页:
[1]