简体   繁体   English

两个可能的字符数的正则表达式

[英]Regex for two possible character counts

I need a regular expression for allowing two diferent character counts. 我需要一个正则表达式来允许两个不同的字符数。 I only want to allow a string whose length is either 5 or 7 characters but not any of the values in between. 我只想允许一个长度为5或7个字符但不包含其中任何值的字符串。

For example: for 5 and 7 例如:5和7

asdfg = ok
asdfgh = fail
asdfghj = ok

Thanks! 谢谢!

You can use this regex: 你可以使用这个正则表达式:

^.{5}(?:.{2})?$

RegEx Demo RegEx演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM