[已解决]请A版及各位正则表达式高手看看这程序错在哪里了?
本帖最后由 sleep365 于 2012-11-10 11:45 编辑想处理一个时间及IP文件,总是有问题卡在正则表达式上面,好象和prel的不兼容,时间没能提出来。#Include <File.au3>
#Include <Array.au3>
Dim $Qstime,$Qetime,$Tmptime,$Tmpip
Local $ipArray, $Var
$ipfile=@ScriptDir&"\ip.txt"
If Not _FileReadToArray($ipfile, $ipArray) Then
MsgBox(4096, "错误", "你要操作的文件并不存在:" + $ipfile)
Exit
EndIf
;_ArrayDisplay($ipArray);显示要查的IP参数
For $i=1 To UBound($ipArray)-1
$Tmptime = StringRegExp($ipArray[$i],"(\d{3}-?\d-\d\h?\d:\d(?::\d)?",1)
$Tmpip = StringRegExp($ipArray[$i],"([\d+.]+)",1)
ConsoleWrite($i&'--'&$ipArray[$i]&'---下标大小:'&UBound($Tmptime)&"/"&$Tmptime&$Tmpip&@CRLF)
Next
文件:
附件不知道能不能显示,以下是文件内容
221.235.69.239 2010-3-89:56:32
119.147.12.191 2010-3-1609:40
59.172.110.160 2010-3-1511:28
59.173.240.82 2010-3-1516:13
59.172.108.90 2010-3-1116:12
119.98.160.201 2010-3-1317:12
221.235.69.239 2012-3-1619:40
119.147.12.191 2010-3-1609:40
219.140.172.210 2010-3-1209:26
59.172.110.160 2010-3-1511:25
59.172.126.131 2010-3-1801:00
59.174.75.97 2010-3-1411:49
59.172.108.123 2010-3-1808:36
219.140.14.253 2010-3-1302:12
58.48.154.192 2010-3-1318:06
59.174.215.127 2010-3-1201:47
111.172.236.198 2010-3-2223:55
58.49.103.165 2010-3-2216:37
59.174.73.177 2010-3-2108:26
111.172.95.81 2010-3-502:15
58.49.241.186 2010-3-1314:37
59.174.21.8 2010-3-1911:26
58.48.66.28 2010-3-2321:43
58.49.209.199 2009-2-213:44
58.49.229.30 2009-2-2522:16
221.232.138.14 2009-2-1116:17
61.183.68.55 2009-2-2509:30
58.49.178.103 2009-2-2409:24
59.173.220.89 2009-2-2308:33
59.172.125.34 2009-2-2417:40
219.140.69.20 2009-2-2317:20
59.173.20.82 2009-2-2519:56
192.96.135.199 2009-2-2517:30 $Tmptime = StringRegExp($str,"(\d{3}-?\d-?\d\s*?\d:\d(?::\d)?)",1)
OR
$Tmptime = StringRegExp($str,"((?:19|20)\d\d-(?:0?|1)-(?:0?||3)\s+(?:0?|1|2)\:(?:)(?:\:)?)",1) 回复 1# sleep365
不明白你什么意思,乱搞了一下提出时间的
### 友情提示:本脚本由 Au3.REHelper 于 2012/10/31 15:32 自动生成,不保证其正确性,请自行测试 ###
#include <Array.au3>
Local $Str = _
'221.235.69.239 2010-3-89:56:32' & @CRLF & _
'119.147.12.191 2010-3-1609:40' & @CRLF & _
'59.172.110.160 2010-3-1511:28' & @CRLF & _
'59.173.240.82 2010-3-1516:13' & @CRLF & _
'59.172.108.90 2010-3-1116:12' & @CRLF & _
'119.98.160.201 2010-3-1317:12' & @CRLF & _
'221.235.69.239 2012-3-1619:40' & @CRLF & _
'119.147.12.191 2010-3-1609:40' & @CRLF & _
'219.140.172.210 2010-3-1209:26' & @CRLF & _
'59.172.110.160 2010-3-1511:25' & @CRLF & _
'59.172.126.131 2010-3-1801:00' & @CRLF & _
'59.174.75.97 2010-3-1411:49' & @CRLF & _
'59.172.108.123 2010-3-1808:36' & @CRLF & _
'219.140.14.253 2010-3-1302:12' & @CRLF & _
'58.48.154.192 2010-3-1318:06' & @CRLF & _
'59.174.215.127 2010-3-1201:47' & @CRLF & _
'111.172.236.198 2010-3-2223:55' & @CRLF & _
'58.49.103.165 2010-3-2216:37' & @CRLF & _
'59.174.73.177 2010-3-2108:26' & @CRLF & _
'111.172.95.81 2010-3-502:15' & @CRLF & _
'58.49.241.186 2010-3-1314:37' & @CRLF & _
'59.174.21.8 2010-3-1911:26' & @CRLF & _
'58.48.66.28 2010-3-2321:43' & @CRLF & _
'58.49.209.199 2009-2-213:44' & @CRLF & _
'58.49.229.30 2009-2-2522:16' & @CRLF & _
'221.232.138.14 2009-2-1116:17' & @CRLF & _
'61.183.68.55 2009-2-2509:30' & @CRLF & _
'58.49.178.103 2009-2-2409:24' & @CRLF & _
'59.173.220.89 2009-2-2308:33' & @CRLF & _
'59.172.125.34 2009-2-2417:40' & @CRLF & _
'219.140.69.20 2009-2-2317:20' & @CRLF & _
'59.173.20.82 2009-2-2519:56' & @CRLF & _
'192.96.135.199 2009-2-2517:30'
MsgBox(0, '原字符串', $Str)
Local $Test = StringRegExp($str, '\d{4}-\d{1,2}-\d{1,2}\d{1,2}:\d{1,2}', 3)
If Not @Error Then MsgBox(0, '匹配数量: ' & UBound($Test), '其中元素为: ' & $Test)
_ArrayDisplay($Test, UBound($Test))
如果理解错了,望见谅~~{:face (396):} 研究了一下午发现还是时间的正则表达式有问题,改成下面的就好了。谢谢annybaby 和seeyou 的热心回复!
$Tmptime = StringRegExp($Var,'\d{3}-?\d-?\d\h+?\d:\d(?::\d)?',2)
页:
[1]