I am new to regular expression. I need a regular expression to validate single digit within range of [1-5] followed by alphabet [A-C] and followed by optional alphabet [X-Z]

  • 1A (Valid)
  • 2BZ (Valid)
  • 7B (Invalid)
有帮助吗?

解决方案

What you tried is right, except you're missing the start and end characters, so it's succeeding on a partial match.

You need:

^[1-5][a-cA-C][x-zX-Z]?$

其他提示

Use online testers to validate it:

[1-5]+[A-C]+[X-Z]*

regexpal

gskinner

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top