Is there any regex (!) which can test if a string contains 3 digits ( never-mind the order) ?
(at least 3 digits. also I be happy to see the exact 3 solution.( if you're kind ))
example :
abk2d5k6 //3 digits
abk25k6d //same here //3 digits
my fail tries :
.+?(?=\d){3}
Thanks.
(only regex solutions please , for learning purpose.).
Well, for the learning purpose, I suggest to read through this very comprehensive tutorial.
Otherwise, the JavaScript regex would probably look something like this:
if you want to make sure that there are at least three digits:
/^(?:\D*\d){3}/
Or if you want to make sure that there are exactly three digits:
/^(?:\D*\d){3}\D*$/
\D
is any non-digit character. *
allows 0 or more of those. \d
is any digit character. {3}
repeats the subpattern 3 times. And ^
and $
mark the start and end of the string, respectively.
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