[英]regex match more than one zero
如標題所示,我需要一種在數字$
的末尾匹配多個零的方法。
100 //match
10 // no match
4000 // match
340 // no match
74003 //no match
我正在使用php,如果那很重要。
嘗試: 0+(?!(0))$
0[0-9]+$
$regex = "/0{2,}$/";
var_dump(preg_match($regex, "4000"));
php> $regex = "/0{2,}$/"
php> preg_match($regex, "100")
php> echo preg_match($regex, "100")
1
php> echo preg_match($regex, "10")
0
php> echo preg_match($regex, "4000")
1
php> echo preg_match($regex, "340")
0
php> echo preg_match($regex, "74003")
0
php>
如果數字必須以非零開頭:
/^[1-9]+00+$/
如果數字可以以零開頭:
/^\d*00+$/
如果您只想檢查最后2位數字是否為0,則可以使用
if($number % 100 == 0){
//0 will be here too, if you need not it try to add (and $number!=0)
}
regexp在這里會有點矯kill過正
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.