我在试图找出符合以下条件的正确PHP正则表达式时遇到了问题:
- 接受所有UTF-8字符
- 接受数字
- 接受2-16个字符之间的字符串
- 排除"@"符号
- 接受所有其他符号,例如:"!#$%^&*))¶£"
- 允许字符之间有一个空格,但不能有多个空格
- 不带尾随空格通过,例如:
"Hello World!" //should be true
" Hello World! " //should be false
"Hello World!" //should be false
以下示例应该失败:
"a" //should fail because the length is less than 2
"whatsup@gmail.com" //should be false because of @ symbol
应通过以下示例:
"£ª¡™ƒ˚å 象形字 123" //should be true
What's up? 123" //should be true
"!#$%^&*(){}-_+" //should be true
到目前为止,我拥有的是:
/^((?!@).)*$/
这个PHP正则表达式目前接受字符,不包括@符号,还包括数字。
任何帮助都将不胜感激!
您可以使用这个基于前瞻性的正则表达式来满足所有条件:
/^(?=.{2,16}$)[^@'s]+(?:'h[^@'s]+)*$/gum
RegEx演示