How do i preg开发者_StackOverflow社区_match an string to match the following format in php:
$m="123/456789/01";
if(pregmatch(????, $m){
// match
}else{
// doesn't match
}
i.e. 3 digits + "/" + 6 digits + "/" + 2 digits.
This is my try :)
if(preg_match('/[0-9]{3}\/[0-9]{6}\/[0-9]{2}/', $m)
{
// match
}
else
{
// Doesn't match
}
if (preg_match("#\d{3}/\d{6}/\d{2}#", $string)) {
// yeah
} else {
// nope
}
have a look at Pattern Syntax specifically Escape sequences.
Depending on what you would like to parse, regular expressions are not always needed:
$m="123/456789/01";
if(3 == count(sscanf($m, '%d/%d/%d'))) {
// match
}else{
// doesn't match
}
精彩评论