Alphanumeric regular expression for letters and numbers only

I want to match an alphanumeric string containing at least one letter and one number. Is there an easy way to combine the following into a single regular expression?

strValue.matches("[A-Z0-9]+") && strValue.matches(".*[AZ].*") && strValue.matches(".*[0-9].*") 
+4
source share
1 answer

Use the expression "look ahead."

 strValue.matches("^(?=.*[AZ])(?=.*\\d)[AZ\\d]+$") 
+6
source

Source: https://habr.com/ru/post/1440341/


All Articles