'RegEx SQL Select not matched

I have this regex

(?i)(sql.*[\s\S]select.*[\s\S]from[\s\S]*?\;)

This one is matched

SQL SELECT Distinct Field1,Field2
FROM Table1
;

But this one is not matched

SQL SELECT Distinct 
     Field,
     Field2
FROM Table1
;

And this one also not:

SQL 
SELECT Field,Field2
FROM Table1;

Why does this happen?

I changed my regex to

(?im)^sql[\s\S]*?^;$

and now the first and the second one are matched, but not the third one.

https://regex101.com/r/qLUbBh/3



Solution 1:[1]

(?im)^sql[\s\S]*?;$

This works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martijn Olivier