I'm not sure if a "Regex Learning Disability" is a real thing... But if it is, I have it! LOL
I'm working with sections from INI files that get assigned to a variable, then manipulated. At one stage, I need to locate the word "Optional" in the first key name that it appears in, and replace the word with "OptX".
The rest of the key name should remain. So if the key is "Key1 Optional key=" it gets changed to "Key1 OptX key=". However, if "Optional" appears in a key value, that should be ignored. I can't simply use the regex .*Optional.*=, because that will erroneously match the word in
Code: Select all
key1 blah key=value Optional this value
key2=blah blah
Does that make sense? My feeble attempt is below.
Code: Select all
; Not working code.
MyEntry =
(
key1 Optional key=value Optional value
key2=blah
Also Optional blah
)
MyEntry := RegExReplace(MyEntry, "i)(.*(?!\R))Optional(.*(?!\R)=)", "$1OptX$2",,1)
MsgBox % MyEntry