1

i`m trying find an regular expression for java that match all select statement queries that is not preceding by some keyword like insert,update,delete,procedure,etc:

At moment at got this:

^(?!insert|delete|update|procedure) {0,}select.*?;$ gims

but not matches right if select starts in new line :

Test cases:

select 1 from dual;
delete from table where id = 
(
select 1 from dual
);
update table set id = 1 where id in (
select 1 from dual);
procedure dsdsd select fdsfds;
PROCEDURE myproc ()
IS
BEGIN
SELECT
 1 from dual;
END myproc ;

Result : matches only select 1 from dual;

this link has test case :

https://regex101.com/r/2wkbOk/1

1 Answers1

0

The "multiline" parameter considers each line independently, so the content on other lines is not considered in your current search. I believe what you're looking for is more of a search across lines in order to consider the statements on lines prior. Try a method utilizing [\s\S] instead of "."

Reference: How to use JavaScript regex over multiple lines?

Community
  • 1
  • 1
Jim Lutz
  • 139
  • 6