如何正则IP的前两段是否相同,谢谢!
本帖最后由 manbutianya 于 2013-4-14 05:07 编辑如何正则两组IP的前两段是否相同,如何表达,正则真头疼!比如现在IP是173.25.0.58,找出文件IP.txt里的多行IP,如果文件里的某行IP前两段是173.25,那么提取这个IP。 Dim $txt, $error = False, $i = 1
Dim $handle = FileOpen("ip.txt")
Do
$txt = FileReadLine($handle, $i)
If @error Then $error = True
$txt = StringRegExp($txt, "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", 3)
If Not @error Then
For $x = 0 To UBound($txt) - 1
If StringInStr($txt[$x], "173.25.") Then MsgBox(0, "", $txt[$x])
Next
EndIf
$i = $i + 1
Until $error = True (?<=\D)173\.25\.\d+\.\d+ 回复 3# afan
A大的更厉害!服了!{:face (189):} Local $file = FileOpen("ip.txt", 0)
; 检查以只读打开的文件
If $file = -1 Then
MsgBox(0, "错误", "无法打开文件.")
Exit
EndIf
$ip = ""
; 读入文本行直到文件结束(EOF)
While 1
Local $line = FileReadLine($file)
If @error = -1 Then ExitLoop
If StringRegExp($line, '173.25.\d+.\d+') Then
$ip = $ip & $line & @CRLF
EndIf
Wend
FileClose($file)
MsgBox(0, "IP : ", $ip) 173.25.0.58也是一个变量,如何表达?
页:
[1]