mac正则提取【已解决】
本帖最后由 redapple2008 于 2024-5-30 10:05 编辑我只需要mac地址,如“51:7B:1D:46:09:88”这一部份,正则怎么处理?
; 正则匹配测试
#include <Array.au3>
Local $sInput = _
"[计算机名]" & @CRLF & _
"计算机名=CLIENT7" & @CRLF & _
"" & @CRLF & _
"IP=10.9.8.7" & @CRLF & _
"子网掩码=255.255.0.0" & @CRLF & _
"网关=10.9.8.254" & @CRLF & _
"首选DNS=10.9.3.22" & @CRLF & _
"" & @CRLF & _
"IP=169.254.208.88" & @CRLF & _
"子网掩码=255.255.0.0" & @CRLF & _
"网关=" & @CRLF & _
"首选DNS=" & @CRLF & _
"备用DNS=" & @CRLF & _
"" & @CRLF & _
"IP=192.168.208.88" & @CRLF & _
"子网掩码=255.255.0.0" & @CRLF & _
"网关=" & @CRLF & _
"首选DNS=" & @CRLF & _
"备用DNS=" & @CRLF & _
""
;MsgBox(262144, "源字符串", $sInput)
Local $aRegExp = StringRegExp($sInput, "({2}:){5}{2}", 4)
_ArrayDisplay ($aRegExp)
Local $aMatch = 0
For $i = 0 To UBound($aRegExp) - 1
$aMatch = $aRegExp[$i]
For $j = 0 To UBound($aMatch) - 1
MsgBox(Default, "RegExp 测试: [" & $i & "] >> " & "", $aMatch[$j])
Next
Next
群友解决了。{2}(?:[:]{2}){5} (?:{2}:){5}{2} {2}(:{2}){5} holley 发表于 2024-5-30 13:10
{2}(:{2}){5}
数组达不到楼主的要求。 redapple2008 发表于 2024-5-30 13:53
数组达不到楼主的要求。
Local $aRegExp = StringRegExp($sInput, "\[({2}(:{2}){5})\]", 3) 还是标志3直接点
Local $aRegExp = StringRegExp($sInput, "\[({2}(?::{2}){5})\]", 3)
Local $aMatches
For $i = 0 To UBound($aRegExp) - 1
$aMatches[$i] = $aRegExp[$i]
Next
_ArrayDisplay($aMatches)
For $i = 0 To UBound($aMatches) - 1
MsgBox(Default, "RegExp 测试: [" & $i & "] >> ", $aMatches[$i])
Next
这种固定格式字符串可以很简单
\[([\w:]+) afan 发表于 2024-5-30 21:21
这种固定格式字符串可以很简单
\[([\w:]+)
大神还是牛,这么简单就解决了。
页:
[1]