Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts

    is this normal regex or my php is messed up

    Learning regex, and i have stumbled on this..

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

    PHP Code:
    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..

    thanks

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    ah i see. i didn't understand right. it is used in this case

    PHP Code:
    echo  preg_match ("/tras*hformers/" "trassssssshformers"); // TRUE 
    thanks. and,
    @moderators
    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...
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •