如何用正则表达式判断括号配对的正确性?VB codeSub fff()Dim oRegAs RegExp As VBScript_RegExp_55.RegEx
如何用正则表达式判断括号配对的正确性?
VB code
Sub fff() Dim oReg As RegExp 'As VBScript_RegExp_55.RegExp Set oReg = New RegExp With oReg .Pattern = "^((0|[1-9][0-9]*)([-+*/](0|[1-9][0-9]*))*[-+*/]?)*(((\()((0|[1-9][0-9]*)+([+*/-](0|[1-9][0-9]*))*)+[-+*/]?)+((\))([-+*/](0|[1-9][0-9]*)[-+*/]?)*)+)*((0|[1-9][0-9]*)([-+*/](0|[1-9][0-9]*))*)*$" s = "1+6*(2+(3-1)/1+(9-5*1))))" Debug.Print .Test(s) End WithEnd Sub
问题是不管正确与否,Debug.print . s = "1+6*(2+(3-1)/1+(9-5*1))" s = "1+6*(2+(3-1)/1+(9-5*1)" s = "1+6*(2+(3-1)/1+(9-5*1))))"