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:
- you ask 3
a's in row , in example there 2 of series possible, first 3a's , last 3a's. match don't specify has happen before or after series of 3a's. - you ask optional
acharacter. input match looking 0 or 1 a's , true feed it, whether containsa's or not.
Comments
Post a Comment