I have tried the below regex for match here http://rubular.com/ but it matches only 3 characters or 3 digits at a time.
^((\d{3})|(\w{3}))$
I need result like this:
123eee
4r43fs
Here you go:
^(?=(?:[a-z]*\d){3})(?=(?:\d*[a-z]){3})\w{6}$
http://regex101.com/r/hO5jY9
If there are at least three digits, at least three letters, and at most six characters, the string has to match.
How does this work?
\w{6}
until the end of the stringThe lookaheads
Let's break down the first lookahead: (?=(?:[a-z]*\d){3})
It asserts that three times ({3}
), at this position in the string, which is the start of the string as asserted by ^
, we are able to match any number of letters, followed by a single digit. This mean there must be at least three digits.
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