I have the following strings:
inputs.test=al
inputs.test=ally^inputs.test=alNOTinputs.test=altogether
inputs.test=ally^inputs.test=alwaysNOTinputs.test=al
inputs.test=alORinputs.test=al^inputs.test=ally^ORinputs.test=al
inputs.test<=alORinputs.test!=alORinputs.test>=al^inputs.test!=ally
I'd like to replace all instances of the string inputs.test[= or != or <= or >= or NOT]al with inputs.test[= or != or <= or >= or NOT]FIXED
All while ignoring substrings after the operator (in this example, always, ally, altogether should be left alone).
inputs.test=FIXED
inputs.test=ally^inputs.test=FIXEDNOTinputs.test=altogether
inputs.test=ally^inputs.test=alwaysNOTinputs.test=FIXED
inputs.test=FIXEDORinputs.test=FIXED^inputs.test=ally^ORinputs.test=FIXED
inputs.test<=FIXEDORinputs.test!=FIXEDORinputs.test>=FIXED^inputs.test!=ally
This may be too complicated to solve with just Regex, just wondering if there is a way.
A little factoring and well placed assertion after the 'al' would make
this regex work.
Just replace with $1FIXED
/(inputs\.test(?:[!<>]?=|NOT))al(?!ly|together|ways)/g
https://regex101.com/r/CDSYuR/1
( # (1 start)
inputs \. test
(?:
[!<>]? =
| NOT
)
) # (1 end)
al
(?! ly | together | ways )