我不擅长正则表达式。
我不想允许任何其他字符,但字母,空格和数字。当然,用户只能输入字母或数字,也可以输入字母和数字,但不能输入其他字符。他还可以在字符串之间放入_,例如:
Hello_World123这可以是可能的字符串。有人能帮我构建一个正则表达式吗?
发布于 2012-01-29 18:34:19
要确保字符串只包含(ASCII)字母数字字符、下划线和空格,请使用
^[\w ]+$说明:
^ # Anchor the regex at the start of the string
[\w ] # Match an alphanumeric character, underscore or space
+ # one or more times
$ # Anchor the regex at the end of the string发布于 2012-01-29 18:28:21
简单地说:
^[\w ]+$解释:
^ matches the start of the string
\w matches any letter, digit, or _, the same as [0-9A-Za-z_]
[\w ] is a set that that matches any character in \w, and space
+ allows one or more characters
$ matches the end of the string发布于 2012-01-29 18:28:18
您可以使用\w \d+ .You可以在http://gskinner.com/RegExr/尝试
https://stackoverflow.com/questions/9052441
复制相似问题