none
RegEx RRS feed

  • Question

  • Hello,
    I have this RegEx but it does not seem to be fully correct as it seems to allow more than two alphanumeric characters

    ^[A-Fa-f\d]{2,}

    My goal is to have two characters. can be either letters or numbers or both letter and number or number and letter

    i.e. A2 or ba or 34 or 3c

    Any thoughts please?

    Thank you

    Monday, January 29, 2018 6:58 AM

Answers

  • This will match the first one or two alphanumeric (up to F) characters:

    ^[A-Fa-f\d]{1,2}

    If you want the regex to fail if there are more matches then you need to match on the end of the string with a $

    ^[A-Fa-f\d]{1,2}$

    • Marked as answer by arkiboys Monday, January 29, 2018 8:25 AM
    Monday, January 29, 2018 8:03 AM