[英]Can Anyone help me out with regular expression in PHP
I dont have much knowledge on Regular expression.我对正则表达式的了解不多。 Help me out if i could achieve the below, Username must need to validate this.
如果我可以实现以下目标,请帮助我,用户名必须需要验证这一点。
I have come up with this regular expression but i cant fulfill all the above.我想出了这个正则表达式,但我不能满足以上所有要求。
/(?<![a-z_|.])([a-z](?:[a-z]|_|.(?!_.))+[a-z]|[a-z]{2})(?![a-z_|.])/
Thanks in advance.提前致谢。
You don't need any lookbehind.你不需要任何回头看。 Simplify your regex to this:
将您的正则表达式简化为:
/^[a-zA-Z0-9](?!(?:.*\.){2}|(?:.*_){2}|.*[._]{2})[a-zA-Z0-9_.]*[a-zA-Z0-9]$/
One way to rome... (simple and easy version)去罗马的一种方式......(简单易行的版本)
if(substr_count($string,'_')<=1 //for rule 4.
&& substr_count($string,'.')<=1 //for rule 4.
&& substr_count($string,'._')===0 //for rule 3.
&& substr_count($string,'_.')===0 //for rule 3.
&& preg_match('/^[^_\.][a-zA-Z]+[^_\.]$/',$string)// for rule 1. & 2.
) {
echo 'Valid';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.