Reputation: 1083
I'm using this regex to check that every letter appears at least once:
String regex = "(?i)(?=.*a)(?=.*b)(?=.*c)(?=.*d)(?=.*e)(?=.*f)(?=.*g)(?=.*h)(?=.*i)(?=.*j)(?=.*k)(?=.*l)(?=.*m)(?=.*n)(?=.*o)(?=.*p)(?=.*q)(?=.*r)(?=.*s)(?=.*t)(?=.*u)(?=.*v)(?=.*w)(?=.*x)(?=.*y)(?=.*z).*
"
Example:
The quick brown fox jumps over the lazy dog
contains all the english letters but my regex is not working.
What I'm doing wrong, or is there any other way to check for pangrams.
Upvotes: 2
Views: 317
Reputation: 18803
There is a significantly simpler and faster way than regular expressions to check that a string is a pangram.
In small steps,
"abcdefghijklmnopqrstuvwxyz"
?Upvotes: 2
Reputation: 67968
(?i)^(?=.*a)(?=.*b)(?=.*c)(?=.*d)(?=.*e)(?=.*f)(?=.*g)(?=.*h)(?=.*i)(?=.*j)(?=.*k)(?=.*l)(?=.*m)(?=.*n)(?=.*o)(?=.*p)(?=.*q)(?=.*r)(?=.*s)(?=.*t)(?=.*u)(?=.*v)(?=.*w)(?=.*x)(?=.*y)(?=.*z).*$
Add anchors
^$
to make a strict match instead of partial matches.
See demo.
https://regex101.com/r/vV1wW6/11
Upvotes: 1