Sangoku
Sangoku

Reputation: 1606

Regex fails on new line

I have an regex expresion which is like this

preg_match("/^\\s*(insert|delete|update|replace|create|drop|alter|use) /i",$query)

This is a part of a pretty old function which is responsible for allmost all of the transactions on our site that we maintain (it is like 8 years old at min...)

Imagine my suprice when this query failed te test on this regex....

"DELETE
                    FROM KursSmer 
                    WHERE   IDKurs = '523' AND
                            IDSmer = '50' AND
                            IDSkolskaGodina = '1' AND
                            JeObavezan = '0'"

It took me about 1h to get the nasty fella... but i did it... there was a \n line element on the end of the first row just next to DELETE word... like DELETE\n

Now, I am left wondering if this can be corrected?

Upvotes: 1

Views: 125

Answers (1)

xdazz
xdazz

Reputation: 160983

You need m modifier for multiple lines.

preg_match("/^\\s*(insert|delete|update|replace|create|drop|alter|use) /im",$query)

Pattern Modifiers

Upvotes: 6

Related Questions