Reputation: 111
I have a requirement to check a string for 16 characters, however I don't want the regex to consider a string that contains 16 digits.
This is the regex I am using \w{16}
but the following two examples matches the regex:
2107260040003208
MDA0ODcyfEFBQ3w3
I want the regex to only match anything like MDA0ODcyfEFBQ3w3
but if the string is 16 digits, I want to ignore it.
appreciate your help in advance
Upvotes: 1
Views: 1060
Reputation: 163467
You can exclude matching digits only using a negative lookahead.
^(?!\d+$)\w{16}$
Without the anchors, you can use a word boundary
\b(?!\d+\b)\w{16}\b
Upvotes: 1