Is there a way how to define regular expression in which will match only if there are at least N unique characters?
Example: (N = 3)
aba => no match
abc => match
abbc => match
ab => no match
abcd => match
Not really, this is not a regex problem.
A much easier solution would be to use a Set like HashSet(T)
Split the string to characters and add each one to the set.
Count the number of elements in the set.
These problems are pretty tricky to do using regex
.
SInce question is tagged as regex
you can try this lookahead
based regex:
(.).*?((?!.*?\1).).*?((?!.*?\2).)
Online Demo: http://regex101.com/r/dH1rP4
It doesn't match:
It matches:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With