Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I am trying to make a regex that will match this pattern,
Must be 40 characters long,
Must contain only letters and numbers,
Must contain no spaces,
Case insensitive,
So far I have come up with this but it does not work;
/^[0-9a-f]+$/i
Thanks
a-f
/^[0-9a-f]{40}$/i
should do the trick. The number in curly brackets defines the number of characters.
Add a comment
Try this regex:
/^[\da-z]{40}$/i
If you really only want the letters a-f then use:
/^[\da-f]{40}$/i
\w
_
Try this:/^[0-9a-z]{40,40}$/i
/^[0-9a-z]{40,40}$/i
{40,40}
{40}
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
a-fbit is odd. You don't want to match on G through Z? Are you trying to match hexadecimal digits? If so, note that the maximum value of a hexadecimal digit is e (decimal 15), not f (decimal 16 is 10 in hex).