Match x out of y groups in Java regex -
is possible write regex pattern in java match, example, 2 out of 3 (or 3 out of 4 etc) groups?
for example, have following regex:
((?=.*\d)(?=.*[a-z])(?=.*[a-z])) which allow patterns match 3 groups - i.e. must contain number , lowercase character , uppercase character. i'd make validate pattern contains @ least 2 out of 3 groups (e.g. number , uppercase character or lower , uppercase characters).
is doable in single statement or going have write separate regexes , loop through them?
you need alternations account possible scenarios:
((?=.*\d)(?=.*[a-z])|(?=.*\d)(?=.*[a-z])|(?=.*[a-z])(?=.*[a-z])) see demo matches whole string matches():
((?=.*\d)(?=.*[a-z])|^(?=.*\d)(?=.*[a-z])|^(?=.*[a-z])(?=.*[a-z])).* 
Comments
Post a Comment