貌似逻辑有问题,比如像 [ xx [aa [bbb] [ccc] aa] yy ] 这样具有同级[ ]的字符串有问题.
修正如下:
#include <Array.au3>
;[5555[44444[333333[222222[111111]]33333]4444]5555]
Local $Str = '[5555[44444[333333[222222[111111]]33333]4444]5555][ xx [aa [bbb] [ccc] aa] yy ]'
$time=TimerInit()
Local $Test = StringRegExp($str, '\[((?>[^\[\]]+)|((?R)))*\]', 4)
If Not @Error Then
Local $Array[UBound($Test)],$Output,$Continus
For $i = 0 To UBound($Test) - 1
$Temp=$Test[$i]
$Array[$i]=$Temp[0]
Next
EndIf
For $i=0 to UBound($Array)-1
$Temp=$Array[$i]
While 1
If Not StringRegExp($Temp,"\[|\]",0) Then ExitLoop
$AA=StringRegExp($Temp, '(\[((?>[^\[\]]+)|(?R))*\])', 3)
If UBound($AA)>1 Then
For $n=0 to UBound($AA)-1 Step 2
$Output&=$AA[$n]&@CRLF
$Temp=StringTrimRight(StringTrimLeft($AA[$n],1),1)
Next
EndIf
WEnd
Next
msgbox(0,TimerDiff($time),$Output)
|