help with regular expression

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

help with regular expression

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

sounds like you want to use preg_match() - play around in the real-time regex tool in my signature.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
Post Reply