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

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -