Regular expression to match 'R33' and 'r34E' [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question 开发者_如何转开发I am looking for a regular expression that matches R33 and r34E. I tried (R|r)[0-9]{2}+[A-Z]{1}
but got an error.
/[rR][0-9]{2}[A-Z]?/
It is an invalid Regular Expression. If you want to have 2 or more digits, {2}+ won't work, you should use {2,}.
(R|r)[0-9]{2,}[A-Z]?
[0-9]{2}+
That plus sign looks wrong. If you take that out:
(R|r)[0-9]{2}[A-Z]?
Appears to do what you want (upper- or lowercase R, two digits, optionally any uppercase letter).
Try ^(R|r)[0-9]{2}$|^(R|r)[0-9]{2}[A-Z]{1}$
Your regex is invalid.
You can use {2}
or +
on an expression, but not both.
精彩评论