开发者

Regex to validate an alphanumeric consecutive string

I'm looking to have a regex that validates any string from 开发者_开发知识库046R to 120R.

Sounds simple enough, but I'm missing something here. this is what I have:

^04[6-9]R|0[5-9][0-9]R|10[0-9]R|11[0-9]R|120R +$

But it's not picking up the 120R as a valid string as well. As can this expression be simplified?

Thanks in advance.


Remove the final  +. Otherwise it requires one or more space after the string 120R to be validated.

Also, | has very low precedence. The ^ and $ should stay outside of the group containing |.

^(?:04[6-9]|0[5-9][0-9]|1[01][0-9]|120)R\s*$


You can exclude certain matches by using negative lookahead, and simplify the regex.

^(?!0[0-3])(?!04[0-5])[01]\d\dR$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜