在字符串中间的正则表达式检查空白 [英] regex check for white space in middle of string
问题描述
你好,我想验证该charcters是字母数字
hello i want to validate that the charcters are alpha numeric
Regex aNum = Regex("[a-z][A-Z][0-9]");
我要添加的选项,有可能是一个白色的空间,所以这将是一个拖字表达
i want to add the option that there might be a white space so it would be a tow word expression
Regex aNum = Regex("[a-z][A-Z][0-9]["\\s]");
或排序
couldent找到正确的sintax
or somthing of the sort couldent find the correct sintax
ID appricate任何恿。
id appricate any incite.
推荐答案
[A-ZA -z0-9\s] {1,}
应为你工作,这其中包含字母数字或空白字符,并且至少一个字符长的字符串相匹配。如果您接受下划线,你也缩短它 [\w\s] {1,}
。
[A-Za-z0-9\s]{1,}
should work for you. It matches any string which contains alphanumeric or whitespace characters and is at least one char long. If you accept underscores, too you shorten it to [\w\s]{1,}
.
您应该添加^和$来验证整个字符串匹配,而不是只有字符串的一部分:
You should add ^ and $ to verify the whole string matches and not only a part of the string:
^ [A-ZA-z0-9\s] {1 ,} $
或 ^ [\w\s] {1,} $
。
这篇关于在字符串中间的正则表达式检查空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!