Reputation: 123
I have a string like this:
((8 eq 'null' or 9 ne 'null') and (1 eq 'uday' ) and (2 eq 'kumar')))
I want to first get 8 eq 'null' or 9 ne 'null'
and replace with true or false and then 1 eq 'uday'
and replace with true or false and after that 2 eq 'kumar'
and replace with true or false. and my final solved expression should look like ((false or true) and (true) and (false))) or (false and true and false).
Can anyone suggest me a solution in VBScript using regex or any other concept?
Upvotes: 0
Views: 2777
Reputation: 200453
Define a regular expression with a capturing group that matches everything that isn't a parenthesis between parentheses:
\(([^()]*)\)
\(...\)
match literal opening and closing parentheses. [^()]*
is a character class that matches everything except parentheses zero or more times (*
). The parentheses around the character class are a capturing group that allows extracting text between parentheses without the parentheses via the SubMatches
collection.
s = "((8 eq 'null' or 9 ne 'null') and (1 eq 'uday' ) and (2 eq 'kumar')))"
Set re = New RegExp
re.Pattern = "\(([^()]*)\)"
re.Global = True 'find all matches in a string, not just the first one
For Each m In re.Execute(s)
WScript.Echo m.SubMatches(0)
Next
Output:
8 eq 'null' or 9 ne 'null' 1 eq 'uday' 2 eq 'kumar'
VBScript cannot evaluate the extracted (sub)expressions for you, though, so you'd need to write further code for that.
Upvotes: 1