正则表达式检查重复的空格字符 [英] Regex to check for duplicate space characters

查看:72
本文介绍了正则表达式检查重复的空格字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个正则表达式来验证文本条目。文本必须介于5到16个字符之间(a-Z加连字符,下划线和空格)。这很好,但它也必须检查没有任何连续的空格。

I have a requirement to write a regex to validate a text entry. The text must be between 5 and 16 characters (a-Z plus hyphen, underscore and space). This is fine but it must also check that there are not any consecutive spaces.

例如。

hello        // PASS
hello there  // PASS
hi there you // PASS
hello  there // FAIL - two spaces between hello and there


推荐答案

你可以使用类似的东西:

You can use something like:

/^(?!.*  )[-a-z_ ]{5,16}\z/i

这篇关于正则表达式检查重复的空格字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆