Regular expression how to prevent a match by following a specific word. Something like the first character to include the look?

I am using regex to match the conditions of a SQL query.



So I don't want to ROWNUM

appear after the keyword WHERE


I have used Lookaheads to achieve this. My regex WHERE (.*(?! ROWNUM )+)

. The problem is that it still matches WHERE ROWNUM < 1000

. If I remove the space before the ROWNUM

regex, then any column with a name ending in ROWNUM

won't match. If I remove the space after WHERE

then it matches even if WHERE

there is no space after the keyword . However, if there are two spaces or any other character between ROWNUM

and the keyword WHERE

(maybe a condition), then this is fine. So if ROWNUM

is the first in the condition, my regex doesn't work.

How can I fix this?


source to share

1 answer

Sounds like you want



which will match WHERE .*

unless .*

it contains a ROWNUM

that is surrounded by word boundaries. ( \b

, "word boundary" is a zero-width assertion indicating a position that is preceded by a letter or number or an underscore, or followed by a letter or number or an underscore, but not both.)



All Articles