[英]PHP regular expression to match exact string
I have string like "ABC 1000", "ABC 1", "ABC 100". 我有类似“ ABC 1000”,“ ABC 1”,“ ABC 100”的字符串。
In above string example, first 3 character ie ABC is fixed every time and then digits, digits can be long upto N numbers. 在上面的字符串示例中,前3个字符(即ABC)每次都是固定的,然后是数字,数字可以长到N个数字。
In 2nd part ie after "ABC " it should always be numberic value, no alphabet, no special symbol. 在第二部分,即“ ABC”之后,它应始终为数字值,无字母,无特殊符号。
So, how can I manage with regular expression. 因此,如何使用正则表达式进行管理。 Please help.
请帮忙。
I have tried with following but failed .. 我尝试了以下但失败了..
$var="ABC 100";
preg_match("/^INR /[0-9]+/", $var)
You have an extra /
in your regular expression. 您的正则表达式中有一个多余的
/
。 It should be: 它应该是:
preg_match('/^ABC \d+/', $var);
You could use this: 您可以使用此:
^[A-Za-z]{3} *\d+$
http://regex101.com/r/gE4mS4 http://regex101.com/r/gE4mS4
$var="ABC 100";
preg_match("/^[A-Za-z]{3} *\d+$/", $var)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.