php - Preg_match() usage with "{}" and "?" -


i'm trying things reggae (pcre) , php.

it seems function pre_match() not work signs {} , ? , i'm wondering why. can me?

here code i'm using example:

    <?php         $search = "aaaah";          //return "valid" while ask 3 "a"         if(preg_match("&a{3}&", $search)){               echo 'valid <br/>';         }else{               echo 'invalid <br/>';         }          //also return "valid" while ask 0 or 1 "a"         if(preg_match("&a?&", $search)){               echo 'valid <br/>';         }else{               echo 'invalid <br/>';         }     ?> 

there must misunderstood. can explain? did not find anywhere. thank in advance!

i'm using mamp mac , coding in utf-8.

the results expected as:

  1. you ask 3 a's in row , in example there 2 of series possible, first 3 a's , last 3 a's. match don't specify has happen before or after series of 3 a's.
  2. you ask optional a character. input match looking 0 or 1 a's , true feed it, whether contains a's or not.

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -