I want to replace lowercase strings within:
SELECT lower1, lower2, lower3 FROM lower4, lower5 WHERE
I use vim replace to replace them to upper case with this regex:
:%s/select\_.*\from\_.*\where/\U&/gic
The regex select\_.*\from\_.*\where is not good when there are other select queries:
for example
it selects everything in this query and affects the strings that cannot be uppercased
SELECT lower1, lower2, lower3 FROM lower4, lower5 WHERE lower1=cannot_be_uppercased
UNION all
SELECT lower1, lower2, lower3 FROM lower6, lower7 WHERE lower1=cannot_be_uppercased
There is non-greedy mode in vim regex. Instead of use
*, use\{-}.The regex
select\_.\{-}from\_.\{-}where, as I think, is what you want.Here is some docs.
:h non-greedy