Jonah Katz
Jonah Katz

Reputation: 5298

Preg_match with regular expressions?

Im trying to catch a posted variable with name that begins with 'price' and ends with a number 0-9 and save the number in a variable $matches. For some reason, the code i have isnt catching it, so obviously my syntax is off. Heres my code..

elseif (preg_match('price/[1-9]/', $field_name, $matches)) {

Upvotes: 1

Views: 127

Answers (1)

xdazz
xdazz

Reputation: 160973

preg_match('/^price([0-9])$/', $field_name, $matches)

The $matches[1] will give you the number.

Upvotes: 1

Related Questions