[英]How to write a regex pattern to match the following patterns in php?
I am taking the value from the user it may contains the following patterns我从用户那里获取价值,它可能包含以下模式
123.00,12.00,1.00,134564.00,123457685.00 123.00,12.00,1.00,134564.00,123457685.00
before Dot it must be varying length minimum one digit to upto 9 digits and after dot it will contain only two ZERO'S .please help me to write the pattern..?在点之前它必须是不同的长度,最小一位到最多 9 位,在点之后它将只包含两个零。请帮我写模式..?
//$pattern must follow above critera
$chk=preg_match($pattern,$request->amount);
if($chk){
//My logic if it's matches the pattern
}
You may use您可以使用
^-?\d{1,9}(?:\.00)?$
See a demo on regex101.com .请参阅regex101.com 上的演示。 This will allow sth.
这将允许某事。 like
-100
, -100.00
but not eg 100.11
.像
-100
, -100.00
但不是例如100.11
。
<?php
// regex version
$request = "123.00,12.00,1.00,134564.00,123457685.00";
$pattern = "/[0-9]{1,9}\.00/";
preg_match_all($pattern,$request, $matches);
print_r($matches);
// simpler version
$values = explode(',', $request);
print_r($values);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.