Waddah Shamroukh
Waddah Shamroukh

Reputation: 111

Regex - 16 characters

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

Answers (1)

The fourth bird
The fourth bird

Reputation: 163467

You can exclude matching digits only using a negative lookahead.

^(?!\d+$)\w{16}$

Regex demo

Without the anchors, you can use a word boundary

\b(?!\d+\b)\w{16}\b

Regex demo

Upvotes: 1

Related Questions