문제

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