i need your help. in vbscript i have a string such as
s = 'Abc' and 'Def' Or 'Ghin' In 'jkl' not 'mnoR' And ... or ... NOT ... iN ...
and i want to uppercase these specific 4 operators (in any combination of lower and upper text): and, or, in, not, to Uppercase.
These operators exist outside the quotes (') - because between them i have business rules. This is important, because, as you can see in 3rd rule ('Ghin') i have 'in' in the name of the rule and in these cases i do not want the text between the quotes (business rule name) to be altered.
How can i solve this in vbscript, preferently using RegEx?
TIA
EDIT: Thanks for your help.
Sorry, but i forgot to mention one detail: i can have text outside the quotes, namely "(" , ")", "[","]" or conditions as "1 = 1", but again: the operators to be changed exist outside the quotes and inside quotes nothing is done.
Using the previous example: s = "('abc' and ['Def' Or 'Ghin'] In 'jkl' not 1=1 AND 'mnoR' And 'pqr' or 'xyz' NOT 'lmn' iN 'Opq')"
s = "('abc' AND ['Def' OR 'Ghin'] IN 'jkl' NOT 1=1 AND 'mnoR' AND 'pqr' OR 'xyz' NOT 'lmn' IN 'Opq')"
In other languages you may use a fancy look around pattern to (logically) apply a regexp to parts of your input only, in VBScript you should use either a regexp replace function with a state or Split().
Demo script for the first alternative:
output:
Using regular expressions is a must?
Something like this should work
I would agree a regex solution is the way to go. But it seems to me that you could just search for your keywords surrounded by spaces, unless of course your business rules include that type of pattern as well.
This will find your keywords (on their own, not contained within another word) and replace any instances with uppercase versions.
Keeping the method exposed by Ekkehard solution, but translating the state variable into the regular expression.
It has the drawback of a string concatenation inside the function, but it only gets called for the found operators and not for the quotes.