需要正则表达式帮助 [英] help with regex needed
本文介绍了需要正则表达式帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个正则表达式:
字符串是字母数字,前半部分正好有 6 个字符,后跟连字符(可选)后跟可选的 4 个字符:(后半部分不能超过 4 个字符)
所以以下任何一项都是有效的
11111A111111-1111111-年yyyyy-989yyyyyy-9090
我认为这个表达式 /[a-zA-Z0-9]([-])?[a-zA-Z0-9]{5,10}$/;
应该有效,但是我无法让它正常工作.
任何帮助将不胜感激,
解决方案
^[a-zA-Z0-9]{6}(-[A-Za-z0-9]{1,4})?$预>I need a regular expression for which:
the string is alphanumeric and have exactly 6 characters in the first half followed by hyphen(optional) followed by optional 4 characters:(cannot have more than 4 characters in the second half)
so any of the following is valid
11111A 111111-1 111111-yy yyyyy-989 yyyyyy-9090
i thought this expression
/[a-zA-Z0-9]([-])?[a-zA-Z0-9]{5,10}$/;
should work but i m unable to get it working correctly.Any help will be appreciated,
解决方案^[a-zA-Z0-9]{6}(-[A-Za-z0-9]{1,4})?$
这篇关于需要正则表达式帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文