Forum Moderators: coopster

Message Too Old, No Replies

preg match help

         

FiRe

11:31 am on Oct 28, 2007 (gmt 0)

10+ Year Member



preg_match('/itemname+[0-9]?/i', $name, $match);

Trying to extract the number from itemname, e.g. "itemname4" or "itemname193" would give me 4 or 193, but the number is optional so if it was just "itemname" I would have a blank result... Any help? My regex is not so hot... thanks!

adb64

12:14 pm on Oct 28, 2007 (gmt 0)

10+ Year Member



Use the following regexp:

preg_match('/itemname([0-9]*)/i', $name, $match);

$match[1] will contain the number, or is empty when only itemname is given.
The + you had in the regexp means 1 or more e characters which is probably not want you want.

Regards,

Arjan