【问题标题】:validating space in alphanumeric string thru regular expression通过正则表达式验证字母数字字符串中的空格
【发布时间】:2012-03-04 15:28:42
【问题描述】:

我正在使用以下正则表达式

"[a-zA-Z0-9 \s]{4,}" 

验证带有空格且最小长度为 4 的字母数字条目。但它不接受空格。我在这里错过了什么。

【问题讨论】:

  • 我怀疑nsregularexpression 标签无效,但我要离开它,因为答案是指 Apple 文档,如果没有该标签,这将毫无意义。

标签: regex nsregularexpression


【解决方案1】:

here 上的这个引用,在标志选项下说:

xIf set, allow use of white space and #comments within patterns

听起来您需要设置此x 标志选项才能使空白起作用。如果我理解正确,您的正则表达式应该类似于

"(?x)[a-zA-Z0-9 \s]{4,}"

【讨论】:

  • (/^\s*$/) 我用它来验证空格。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多