正则表达式匹配任何字符和数字但没有空格和@符号

时间:2014-12-12 14:35:24

标签: regex

我只想要一个正则表达式可以帮助我验证输入允许任何字符数字但没有空格和@符号,任何想法?我不是很擅长正则表达式,我知道使用^ \ S + $来避免空间,并使用^ [^ / \()@] * $来避免@符号,但如何将这两者结合在一起?谢谢!

2 个答案:

答案 0 :(得分:0)

\s添加到角色类

^[^@\s]+$
  • \s匹配空格。

  • 否定字符类[^ ]可确保除@或空格以外的任何内容匹配

Regex Example

答案 1 :(得分:0)

你可以使用否定的字符类。

^[^\s@]+$

说明:

^             # the beginning of the string
 [^\s@]+      #   any character except: whitespace, '@' (1 or more times)
$             # before an optional \n, and the end of the string
相关问题