I need some way to find words that contain any combination of characters and digits but exactly 4 digits only, and at least one character.
EXAMPLE:
a1a1a1a1 // Match
1234 // NO match (no characters)
a1a1a1a1a1 // NO match
ab2b2 // NO match
cd12 // NO match
z9989 // Match
1ab26a9 // Match
1ab1c1 // NO match
12345 // NO match
24 // NO match
a2b2c2d2 // Match
ab11cd22dd33 // NO match
Assuming you only need ASCII, and you can only access the (fairly primitive) regexp constructs of
grep
, the following should be pretty close:The regex for that is:
With
grep
:Do it in one pattern with Perl:
The funky
[^\W\d_]
character class is a cosmopolitan way to spell[A-Za-z]
: it catches all letters rather than only the English ones.