不正确的正则表达式分配
Incorrect regex assignment
我希望我的正则表达式分配这些值,并且只分配这些值:1a、1b、2a、2b、3a、3b、n。似乎我的正则表达式不起作用:“[([1-3][a-b])(n)]”。为什么它不 "see" 包含 [1-3][a-b] 的圆括号以及这个正则表达式应该如何正确工作?
I'd like my regex to assign these and only these values: 1a
, 1b
, 2a
, 2b
, 3a, 3b
, n
.
也就是说,你需要使用
.matches("[1-3][ab]|n")
在您的模式中,外部方括号创建了一个字符 class,内部方括号仅被视为 unions,整个 "[([1-3][a-b])(n)]"
仅匹配 1 个字符((
,或1
到3
数字,或a
到b
字母等
我希望我的正则表达式分配这些值,并且只分配这些值:1a、1b、2a、2b、3a、3b、n。似乎我的正则表达式不起作用:“[([1-3][a-b])(n)]”。为什么它不 "see" 包含 [1-3][a-b] 的圆括号以及这个正则表达式应该如何正确工作?
I'd like my regex to assign these and only these values:
1a
,1b
,2a
,2b
, 3a,3b
,n
.
也就是说,你需要使用
.matches("[1-3][ab]|n")
在您的模式中,外部方括号创建了一个字符 class,内部方括号仅被视为 unions,整个 "[([1-3][a-b])(n)]"
仅匹配 1 个字符((
,或1
到3
数字,或a
到b
字母等