找回密码
 加入
搜索
查看: 2472|回复: 5

始终还是不知道在AU3里怎么使用正则表达式提取字符串,请教。

  [复制链接]
发表于 2008-10-9 14:27:56 | 显示全部楼层 |阅读模式
比如我想要做一个NOD32的ID获取器。从以下字符里提取出用户ID跟密码。

document.all.updatetime.innerHTML="2008-10-9 0:45:59"
document.all.virusver.innerHTML="v.3505 (20081008)"
document.all.nod32ids.innerHTML="<font color=\"#008003\">UserName: EAV-06072941<br />PassWord: 4ju7ecwbxh<br />Version: ESS, EAV, 2.*</font><br /><br /><font color=\"#008003\">UserName: EAV-06360823<br />PassWord: 7st5sxn6ke<br />Version: EAV, 2.*</font><br /><br /><font color=\"#008003\">UserName: EAV-06167002<br />PassWord: nc3aeuuud7<br />Version: EAV, 2.*</font><br /><br /><font color=\"#008003\">UserName: EAV-06166967<br />PassWord: v247rvtxfd<br />Version: EAV, 2.*</font><br /><br /><font color=\"#008003\">UserName: EAV-06167065<br />PassWord: r6b66tbm2t<br />Version: EAV, 2.*</font><br /><br /><font color=\"#008003\">UserName: EAV-06167033<br />PassWord: jnj5bfknua<br />Version: EAV, 2.*</font><br /><br /><font color=\"#008003\">UserName: EAV-06360737<br />PassWord: k2fdmjd533<br />Version: EAV, 2.*<br />Expiry Date: 2009-04-07</font><br /><br /><font color=\"#008003\">UserName: EAV-05791354<br />PassWord: dwmr5useeu<br />Version: ESS, EAV, 2.*<br />Expiry Date: 2009-01-03</font><br /><br /><font color=\"#008003\">UserName: EAV-05791353<br />PassWord: 78mua2frd2<br />Version: ESS, EAV, 2.*<br />Expiry Date: 2009-01-03</font><br /><br /><font color=\"#008003\">UserName: EAV-05791347<br />PassWord: 3nhsj7aujx<br />Version: ESS, EAV, 2.*<br />Expiry Date: 2009-01-03</font><br /><br /><font color=\"#008003\">UserName: EAV-06074396<br />PassWord: jcm57hmj7x<br />Version: EAV, 2.*<br />Expiry Date: 2009-04-06</font><br /><br /><font color=\"#008003\">UserName: EAV-06280986<br />PassWord: xah5f6wasb<br />Version: EAV, 2.*<br />Expiry Date: 2009-04-06</font><br /><br /><font color=\"#008003\">UserName: EAV-05334913<br />PassWord: 77aau7vdcs<br />Version: EAV, 2.*<br />Expiry Date: 2009-03-19</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06073992<br />PassWord: 7725wfvtxp</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05943272<br />PassWord: dtfv3cnx6j</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06408712<br />PassWord: cavh7df8nf</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06217551<br />PassWord: huncn6k4mt</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06217386<br />PassWord: 62h7v82n7r</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05832072<br />PassWord: khh2kuvhek</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06057472<br />PassWord: as4hcnxnsh</font><br /><br /><font color=\"#FF0003\">UserName: EAV-04827865<br />PassWord: hacxhr8nsa</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05936616<br />PassWord: sr6t5pa6u7</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06110487<br />PassWord: ucx5h47uca</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06110426<br />PassWord: 27p5mx4ssf</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05922380<br />PassWord: 6ur6ub5t6t</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05922372<br />PassWord: ufb6d77bme</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05769641<br />PassWord: whewp54j2s</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05769619<br />PassWord: s4627pspkt</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05769611<br />PassWord: knasw7j5kp</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05769591<br />PassWord: 5prprber6a</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05866221<br />PassWord: 5de48bu53x</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06003199<br />PassWord: 8p75wp3fc6</font><br /><br /><font color=\"#FF0003\">UserName: EAV-04827872<br />PassWord: j4552eacxb</font><br /><br /><font color=\"#FF0003\">UserName: EAV-04807128<br />PassWord: 8asdmsu5dm</font><br /><br /><font color=\"#FF0003\">UserName: EAV-06156310<br />PassWord: 6hkuebnd64</font><br /><br /><font color=\"#FF0003\">UserName: EAV-04827869<br />PassWord: k8vrpcvjbk</font><br /><br /><font color=\"#FF0003\">UserName: EAV-04897522<br />PassWord: rnxvfhenmh</font><br /><br /><font color=\"#FF0003\">UserName: EAV-04947652<br />PassWord: 42awxraskx</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05231224<br />PassWord: 3mxkms5x58</font><br /><br /><font color=\"#FF0003\">UserName: EAV-05226716<br />PassWord: svh5kmbrsn</font><br /><br />"


$user = StringRegExp($id, "\bUser\b\.*\EAV-\d{8}", 1, 1)    # 这一句应该怎么写? $id为 文件读取内容变量。

初学正则,理解不好。请高手指教。
 楼主| 发表于 2008-10-9 14:29:04 | 显示全部楼层
在线等高手解答。
发表于 2008-10-9 15:36:42 | 显示全部楼层
 楼主| 发表于 2008-10-9 16:24:01 | 显示全部楼层
假如我要提取  UserName: EAV-05226716  这一段字符的话。使用如下表达式对不对的?

$user = StringRegExp($id, "^b{2}.sw{3}-d{8}", 1)
MsgBox(64, "test", $user[0], 5)



希望高手指点一下错在哪? 始终是提取不出这段字符。
发表于 2008-10-9 23:15:22 | 显示全部楼层
将楼主的网页格式保存为桌面上的test.htm后:


#include <ie.au3>
$URL = @DesktopDir & '\test.htm'
$oIE = _IECreate($URL, 0, 0, 1, 0)
$String = _IEDocReadHTML($oIE)
Local $Offset1 = 1, $Offset2 = 1, $SHOW = ''

While 1
    $Strings1 = StringRegExp($String, '(?i)(UserName: EAV-\d{8})', 1, $Offset1)
    If @error = 0 Then
        $Offset1 = @extended
    Else
        ExitLoop
    EndIf
    $StringS2 = StringRegExp($String, '(?i)(PassWord: .{10})', 1, $Offset2)
    If @error = 0 Then
        $Offset2 = @extended
    Else
        ExitLoop
    EndIf
    $SHOW &= $Strings1[0] & "        " & $StringS2[0] & @CRLF
WEnd
MsgBox(0,"用户名和密码", $SHOW)


[ 本帖最后由 liongodmien 于 2008-10-10 08:11 编辑 ]
发表于 2008-10-10 08:15:57 | 显示全部楼层

#include <ie.au3>
$URL = @DesktopDir & '\test.htm'
$oIE = _IECreate($URL, 0, 0, 1, 0)
$String = _IEDocReadHTML($oIE)
Local $Offset1 = 1, $Offset2 = 1, $SHOW = ''

While 1
    $Strings1 = StringRegExp($String, 'UserName: EAV-\d{8}', 1, $Offset1)
    If @error = 0 Then
        $Offset1 = @extended
    Else
        ExitLoop
    EndIf
    $StringS2 = StringRegExp($String, 'PassWord: .{10}', 1, $Offset2)
    If @error = 0 Then
        $Offset2 = @extended
    Else
        ExitLoop
    EndIf
    $SHOW &= $Strings1[0] & "  " & $StringS2[0] & @CRLF
WEnd
MsgBox(0,"用户名和密码", $SHOW)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-22 01:13 , Processed in 0.079019 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表