Good morning, guys.
I'm trying to make a regex to capture blocks from CASE WHEN ... END. So, from this string:
iduser + CaSe WhEn ("end") = 0 THEN 'CASE WHEN' ELSE ' END ' END + sum(iduser ) + CASE WHEN LANGUAGE = 3 THEN 4 ELSE 5 END
The blocks are captured:
CaSe WhEn ("end") = 0 THEN 'CASE WHEN' ELSE 'END' END
CASE WHEN LANGUAGE = 3 THEN 4 ELSE 5 END
What I get so far, was the result of a regex that I had done with a lot of sweat to get string in brackets, it looks like this:
(CASE\s*WHEN)([^)]+)(END)
However, there are some problems:
-
([^)]+)
- > This part does not make sense to me, but without it, it works; - I do not want regex to capture blocks in quotation marks (simple or doubles).
-
([^)]+)
- > In addition to making no sense, it causes string with parentheses to not work.
EDIT
The regex is like this now, I was able to evolve a little:
(?i)(CASE\s*WHEN)(\s*.*)(END)
Now it no longer has the meaningless parentheses and is case insensitive. But, you're still not ignoring the quotes. And that modification has stopped picking up all the blocks and is putting them all together in one.
Thank you in advance!