Public Sub ZZ_Replace ()
Const ForReading=1
Const ForWriting=2
Dim strTxt As String 'to find replacement text
Dim expTxt search String (or regular expression) As String '
Dim repTxt As String 'replacement String
Dim s1 As String 'out of the loop is String
Dim s2 As String 'out of the loop is String
The Set objFSO=CreateObject (" Scripting. FileSystemObject ")
The Set objFile=objFSO. OpenTextFile (" c: \ temp. TXT ", ForReading)
StrTxt=objFile. ReadAll
ObjFile. Close
StrTxt=StrReplace (strTxt, \ \ "d \ \ ba \ d + \ \ li \ (((^)) *) \] ([^ \ r \ n] {1})", "[KG - 3] $1 $2 [1] CD#")
The Set objFile=objFSO. OpenTextFile (" c: \ temp. TXT ", ForWriting)
ObjFile. WriteLine strTxt
ObjFile. Close
The Set objFSO=Nothing
The Set objFile=Nothing
End Sub
Now I want to match as there are multiple hollow nested parentheses [*] string (nested might be more complicated than under the cases of actual or simple) :
BC write write [A [[2] + EFG left [35]]]... Behind, there is also a [*]
Should be how to write the most outer layer behind the [*] match again after a replacement? If use greed mode, may be that the string back and many]
CodePudding user response:
Was not very skilled but some regular expressions to regular seems very simple, but the execution efficiency is too low, use the replace functionCodePudding user response:
Regular online test address: http://www.regexp.cnCodePudding user response:
Match with multiple nested string- not to use the legendary regular balance group??
[I'm sorry, the regular of "balanced set of" I'm not]
CodePudding user response:
Is to use the balance, actually balance best writing, writing is the fixed wayCodePudding user response:
Regular for maintenance, efficiency is also low, writing code, although no regular looked so short,