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

[AU3基础] 如何正则IP的前两段是否相同,谢谢!

  [复制链接]
发表于 2013-4-14 04:34:59 | 显示全部楼层 |阅读模式
本帖最后由 manbutianya 于 2013-4-14 05:07 编辑

如何正则两组IP的前两段是否相同,如何表达,正则真头疼!比如现在IP是173.25.0.58,找出文件IP.txt里的多行IP,如果文件里的某行IP前两段是173.25,那么提取这个IP。
发表于 2013-4-14 09:46:04 | 显示全部楼层
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
发表于 2013-4-14 10:40:38 | 显示全部楼层
(?<=\D)173\.25\.\d+\.\d+
发表于 2013-4-14 23:38:32 | 显示全部楼层
回复 3# afan


    A大的更厉害!服了!
发表于 2013-4-15 00:32:22 | 显示全部楼层
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)
 楼主| 发表于 2013-4-15 21:06:23 | 显示全部楼层
173.25.0.58也是一个变量,如何表达?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-18 13:02 , Processed in 0.095110 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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