/    Sign up×
Community /Pin to ProfileBookmark

help with regular expression

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

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehMay 03.2007 — [CODE]/INSERTs+INTOs+([a-z_]+)(?=s)/i[/CODE]
Copy linkTweet thisAlerts:
@NogDogMay 03.2007 — [code=php]
preg_match('/insert into w+b/i', $text, $matches);
[/code]

[b]w[/b] = [a-zA-Z0-9_] (a.k.a any "word character")

[b]b[/b] = word boundary
Copy linkTweet thisAlerts:
@bokehMay 03.2007 — A couple of differences between what I posted and the expression posted by Nogdog. I didn't use [B]w[/B] because it is locale aware so might give unexpected results. Also it wasn't clear if you wanted to capture numbers. The character class is probably more readable for novices too. I used [B]s+[/B] instead of a literal space as this is what is legal in an SQL query (although it might not be what you wanted). I added parenthesis around the character class just in case you wanted to capture the tablename by itself.
×

Success!

Help @jasongr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...