I am trying to use regular expression in drool rule engine to find perticular keywords in sql queries(String). But even simplest regex are not working.
when Query :Bean(Value matches "(\s|\r)(VALUES)(\|\r)")
insert into table values (xyz);
insert into table
insert into table values
You should bear in mind that
matches requires a full string match. So, to match a string with a whole word
VALUES you need to make sure you match the chars before and after the word, and
.* (with a DOTALL modifier) is the usual choice:
(?s)- a DOTALL inline modidier to make
.match any char
.*- any 0+ chars, as many as possible
\\bVALUES\\b- a whole word
\bare word boundaries)
.*- any 0+ chars, as many as possible.
Tto make sure there are specific chars around
VALUES, you may use
or the same with character classes:
Remember that a
\ should be escaped to define a literal
\ and to match a backslash, you need to use 4 backslashes. So,
([\\s)])(VALUES)([\\\\\r]) matches a whitespace or
\ or a CR symbol after the word.