1

I need a sample regular expression to test in Javascript - input starts with one number between 1 to 16 and is followed by 1 letter between A to E only. eg 2B, 8D, 11E, 16A

I have this regex^([1-9]|[0-1][0-6])[A-E]$ but unable to get appropriate result.

Thank you for your time.

askedJun 17, 2020 at 16:46
Manoj Karki's user avatar
2
  • ^(?:[1-9]|1[0-6])[A-E]$CommentedJun 17, 2020 at 16:48
  • Try:(?:1[0-6]|[1-9])[A-E] ... your current pattern is only slightly offCommentedJun 17, 2020 at 16:49

1 Answer1

1

The[0-1][0-6] part matches numbers from00 to16.

You want

^(?:[1-9]|1[0-6])[A-E]$

See theregex demo and aregex graph:

enter image description here

Details

  • ^ - start of string-(?:[1-9]|1[0-6]) - a digit from1 to9 or1 followed with a digit from0 to6
  • [A-E] -A,B,C,D orE
  • $ - end of string.
answeredJun 17, 2020 at 16:58
Wiktor Stribiżew's user avatar
Sign up to request clarification or add additional context in comments.

1 Comment

It worked - many thanks for your time, support and regex useful info.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.