正则表达式判断字符串是否包含字母,数字,符号

str:要判断的字符

1.判断字符串是否包含字母,数字符号

str.matches("^(?:(?=.*[0-9].*)(?=.*[A-Za-z].*)(?=.*[\W].*))[\W0-9A-Za-z]{8,16}$")

2.判断字符串是否包含大写字母

str.matches(".*[A-Z]+.*")

3.判断字符串是否包含小写字母

str.matches(".*[a-z]+.*");

4.判断字符串是否包含字符

str.matches(".*[~!@#$%^&*()_+|<>,.?/:;'\[\]{}"]+.*");

原文地址:https://www.cnblogs.com/Timeouting-Study/p/13715310.html