PDA

View Full Version : Preg match problem. Please help.


ramki067
05-29-2008, 05:01 AM
Hi,
I've two preg_match in the for loop and i've select one based on the input. But i'm getting it wrong. Please help.

1. preg_match('/0x[0-9a-z]/i',$value)
2. preg_match ('/\d+x\d./i/', $value)

The first preg_match SHOULD match inputs having 0x at the starting followed by any alphabets or digits. For ex: 0x11, 0x33.

The second preg_match SHOULD have digits at the start followed by "x"(Letter x) and followed by digits with characters.For ex: 800x600,1920x1080i.

But whatever input i give it takes the first preg_match itself. Please clarify.I'm using these two preg_matches in foreach loop.

Thanks,
ramki.

Inigoesdr
05-29-2008, 07:16 AM
0x[0-9a-z] matches 800x600 and 1920x1080i. You need to be more specific with your patterns, like using the circumflex to mark the beginning of the string. You can find more information about general syntax and modifiers in the manual (http://php.net/regexp.reference).

Example(not tested):
preg_match('/^0x[0-9a-z]+$/i',$value)

ramki067
05-29-2008, 08:42 AM
0x[0-9a-z] matches 800x600 and 1920x1080i. You need to be more specific with your patterns, like using the circumflex to mark the beginning of the string. You can find more information about general syntax and modifiers in the manual (http://php.net/regexp.reference).

Example(not tested):
preg_match('/^0x[0-9a-z]+$/i',$value)

Thanks inigoesdr. It worked!!!