Modifying Regex to Exclude "END;" After "CASE" with Possible Text in Between

57 Views Asked by At

I have a regex pattern to find occurrences of "END;" in a text, but I need to modify it to exclude instances where "END;" appears after a "CASE" statement, even if there are line breaks or any other text in between them. Additionally, I want to ignore all occurrences of "END;" after the first one following a "CASE". Here's the existing regex pattern:

const rightPattern = '\\bEND\\s*;'; How can I adjust this regex to meet the criteria mentioned above, considering the possibility of line breaks or any other text between "CASE" and "END"? Any help is appreciated!

Example input text:

-- Example with END; after CASE CASE WHEN condition1 THEN END; -- Exclude this END;

-- Another instance of END; not following CASE END;

-- Example with line breaks and text between CASE and END; CASE WHEN condition2 THEN someText END; -- Exclude this END;

-- Example with text between CASE and END; CASE WHEN condition3 THEN someText END; -- Exclude this END;

I tried for example something like this: (?<!\bCASE.*)\bEND; But this doesn't support line breaks, and looks only at the first occurence.

0

There are 0 best solutions below