[英]PHP Regular Expression. Must begin with specific word and after any number. Can't have space
I'm trying to figure it out a Regular Expression that matches. 我试图找出匹配的正则表达式。 I looked at a few answers to similar questions but I couldn't figure it out the last part of it.
我看了一些类似问题的答案,但我无法弄清问题的最后一部分。
This is what I got, just want to make sure if it covers everything and it doesn't have false matches... 这就是我得到的,只是想确保它是否覆盖了所有内容并且没有错误匹配...
/^(cdn|ns|CDN|NS)([0-9])*$/
My goal is to match any entry that starts with cdn or ns and have 0 or more numbers (only numbers) after. 我的目标是匹配任何以cdn或ns开头并且之后有0个或多个数字(仅数字)的条目。 It can't have any space before, in the middle or after.
它之前,中间或之后不能有任何空间。
I hope this is not a duplicated, I spent about an hour going through the suggested answers. 我希望这不是重复的,我花了大约一个小时来研究建议的答案。
Thanks! 谢谢!
Use this for one or more spaces. 将其用于一个或多个空格。 Good luck!
祝好运! :)
:)
$regex = "~^(?:cdn|ns) *[0-9]*$~i";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.