View Full Version : is this normal regex or my php is messed up

11-07-2007, 03:47 PM
Learning regex, and i have stumbled on this..

* quantifier matches 0 or more times. is this normal to be true or false

preg_match ("/tras*hformers/" , "trashforsmers"); // FALSE (tutorial says it should be true

preg_match ("/tras*hformers/" , "trashformersss"); // TRUE

i'm wondering couse i found one tutorial, and now when i test it looks like it's wrong.

i guess the whole pattern must be true AND then after the pattern if any 's' were found it will also be true..


11-07-2007, 04:03 PM
the first one looks like a typo (trashforsmers).
the second one matches as the pattern does occur in the right hand side, the extra s's aren't included in the match, they're just ignored.

11-07-2007, 04:22 PM
ah i see. i didn't understand right. it is used in this case

echo preg_match ("/tras*hformers/" , "trassssssshformers"); // TRUE

thanks. and,
i might have some more questions about regex so can i just write them in this thread, or start a new thread every time i bump into problem.
hope you don't mind me asking a bunch of newbie stuffz... :o
if you want you can merge with this http://codingforums.com/showthread.php?t=126981
I started a new thread couse ppl stop responding there