能力有限,一句正则无法完成楼主的要求.
还是写个函数来解决吧.
#include <Array.au3>
Local $Str = _
'111123111' & @CRLF & _
'222123222' & @CRLF & _
'aa123bb' & @CRLF & _
'11231' & @CRLF & _
'21232' & @CRLF & _
'a123a' & @CRLF & _
'b123a'
MsgBox(0, '原字符串', $Str)
$temp=_StringRegExp123($str,0);0为"@123@"形式,1为"=123="
_ArrayDisplay($temp)
$temp=_StringRegExp123($str,1);0为"@123@"形式,1为"=123="
_ArrayDisplay($temp)
func _StringRegExp123($string,$flag)
if $flag=0 Then
Local $Test = StringRegExp($string, '(.{2,})(123)(\1)', 3)
Else
Local $Test = StringRegExp($string, '(.)(123)(\1)', 3)
EndIf
local $return[UBound($Test)/3]
local $k=0
for $i=0 to UBound($Test)-1 step 3
$return[$k]=$Test[$i]&$Test[$i+1]&$Test[$i+2]
$k+=1
Next
Return $return
EndFunc
|