本帖最后由 hnfeng 于 2016-4-14 13:09 编辑
为了兼顾IP所在文本的各种情况,麻烦 @afan 再改改正则表达式。
目前的代码,当 IP 前后紧跟英文字符时,替换失败(结果中有部分IP未被替换)
#include <Array.au3>
Global $Text = "asasaf111.111.111.1aaa" & @CRLF & _
"asasaf111.111.111.1" & @CRLF & _
"111.111.111.11aaaa" & @CRLF & _
"asasaf111.111.111.11aaa" & @CRLF & _
"asasaf 111.111.111.111" & @CRLF & _
"asasaf 111.111.111.111aaaa" & @CRLF & _
"asasaf 111.111.111.111"
Global $a_IP_Add[3][2] = [["111.111.111.1", "地址11111111111"], _
["111.111.111.11", "地址22222222222222222222"], _
["111.111.111.111", "地址33333"]]
For $i = 0 To UBound($a_IP_Add) - 1
$Text = StringRegExpReplace($Text, '\b\Q' & $a_IP_Add[$i][0] & '\E(?=\D|$)', $a_IP_Add[$i][0] & ' [' & $a_IP_Add[$i][1] & ']')
Next
MsgBox(0, "替换", $Text)
|