I’ve got a string which contains q="AWORD" and I want to replace q="AWORD" with q="THEWORD". However, I don’t know what AWORD is.. is it possible to combine a string and a regex to allow me to replace the parameter without knowing it’s value? This is what I’ve got thus far…
globalparam.replace('q="/+./"', 'q="AWORD"');
What you have is just a string, not a regular expression. I think this is what you want:
I don’t know how you got the idea why you have to “combine” a string and a regular expression, but a regex does not need to exist of wildcards only. A regex is like a pattern that can contain wildcards but otherwise will try to match the exact characters given.
The expression shown above works as follows:
q=": Match the charactersq,=and"..+?": Match any character (.) up to (and including) the next". There must be at least one character (+) and the match is non-greedy (?), meaning it tries to match as few characters as possible. Otherwise, if you used.+", it would match all characters up to the last quotation mark in the string.Learn more about regular expressions.