Page 1 of 1

help with regular expression

Posted: Thu May 03, 2007 8:03 am
by jasongr
Hi people

I need help with a simple regular expression.
I am given a PHP buffer. I need to know if the following phrase appears in it:
INSERT INTO <table name>

where <table name> is a name of a sql table. It can contain characters (upper and lower) and underscores.
Here are possible values:
INSERT INTO mytable
INSERT INTO another_table

right after the name of the table needs to be a whitespace or newline.

can anyone help me with that?

regards
Jason

Posted: Thu May 03, 2007 5:19 pm
by Kieran Huggins
sounds like you want to use preg_match() - play around in the real-time regex tool in my signature.

Posted: Thu May 03, 2007 5:23 pm
by Ambush Commander

Code: Select all

"/^INSERT INTO [A-Za-z0-9_]+[ \n]\$/"
We will leave it as an exercise to the reader to determine how this works and how to use it.