Search code examples
regexposixposix-ere

regex help, accepting range of hex characters


I wish to accept hex characters only, case doesn't matter, so [0-9a-fA-F] but I only want to accept strings between 10 and 64 characters, what is the best way to do this range?

I am using POSIX Basic Regular Expressions.


Solution

  • Use quantifiers

    ^[0-9a-fA-F]{10,64}$
    

    w{n} means match w n times exactly where n is a positive number

    w{n,m} means match w between n to m times

    w{n,} means match w n to many times

    ^ is start of the string

    $ is end of the string

    Now here ^,$ are essential else it would match anywhere in between