[英]regular expression to validate 2 alphanumerics
I have the follow pattern to validate a string, it has to validate 4 letters , 6 numbers , 6 letters and 2 alphanumerics , but with my current pattern I cant get a valid test 我有以下模式来验证字符串,它必须验证4个字母 , 6个数字 , 6个字母和2个字母数字 ,但是使用我当前的模式,我无法获得有效的测试
Pattern.compile("[A-Za-z]{4}\\d{6}\\w{6}\\[A-ZÑa-zñ0-9\\- ]{2}");
I think my pattern it's wrong, because I'm not shure about this [A-ZÑa-zñ0-9\\\\- ]{2}
我认为我的模式是错误的,因为我对这个[A-ZÑa-zñ0-9\\\\- ]{2}
Can you please help me? 你能帮我么?
A few things off on your regex. 正则表达式上有一些问题。
You have extra backslashes in your digit and word matching. 您的数字和单词匹配中有多余的反斜杠。 Change from \\\\d
to \\d
and \\\\w
to \\w
. 从\\\\d
更改为\\d
,从\\\\w
更改为\\w
。
The \\\\
is not needed. 不需要\\\\
。
Your end regex is invalid syntax. 您的最终正则表达式语法无效。 Just remove the "\\\\- "
bit. 只需删除"\\\\- "
位。
You can also slim down your initial part to be \\w
instead of [A-Za-z]
. 您也可以将初始部分减为\\w
而不是[A-Za-z]
。 So, you're new regex should look like: 因此,您是新的正则表达式应如下所示:
"\w{4}\d{6}\w{6}[A-ZÑa-zñ0-9]{2}"
That is if you're okay with the only non-ascii characters being Ñ and ñ in your last two alphanumerics. 那就是您可以接受的情况,在最后两个字母数字中唯一的非ASCII字符是Ñ和ñ。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.