I am making a regular expression for work to search though files and find SQL queries, it works perfectly accept it can not cater to multiple lines. How do I make this indifferent to multiple lines?
(((SELECT|DELETE) ([A-Za-z0-9-\*,`\._ ]+) FROM)|(INSERT INTO)|(UPDATE ([A-Za-z0-9-\*,`]+) SET))
Thats for the advice, but thats not the issue. I do not know when there will be a breakline, I am searching over more than 50,000 files for what I believe will amount to 1,000 queries which where by a very inconsistent programmer.
In other words, it currently will match
SELECT `something` FROM `db` WHERE 1
But it will not match
I need it to match both, no matter where the line break is
Have you tried using the s modifier? Depending on how you're feeding the data in to your regex, it may be a quick and dirty solution to your problem (the s modifier treats any string/block that the regular expression is traversing as a single line).
Outside of that, Salathe was sending you in the right direction. You can use \r, \n or \v to check for the possibility of newlines or vertical whitespace, just the same as you would use 0-9 to check for the letters 0-9, or _ to check for underscores, etc... you just have to incorporate them into the regex whereever you think there could eventually be one. Give it the option to find it. For example,
Adding the ability to have whitespace in the two character classes, combined with using the x modifier, would help. In order to match line breaks you have to tell the regex engine where to expect them, there's no magic allow/disallow switch.