Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 密码验证中的正则表达式不起作用?_Java_Android - Fatal编程技术网

Java 密码验证中的正则表达式不起作用?

Java 密码验证中的正则表达式不起作用?,java,android,Java,Android,在我的Android项目中,我有一个正则表达式和一个字符串,其中应该有匹配的表达式。问题是,我只是没有找到?请看我的代码和我的问题是什么,请分类 public void validatePassword(String gettext) { Toast.makeText(getApplicationContext(),gettext,Toast.LENGTH_LONG).show(); String regex ="((?=.*[0-9])(?=.*[a-z]) (?=.*[A-Z

在我的Android项目中,我有一个正则表达式和一个字符串,其中应该有匹配的表达式。问题是,我只是没有找到?请看我的代码和我的问题是什么,请分类

public void validatePassword(String gettext) {
    Toast.makeText(getApplicationContext(),gettext,Toast.LENGTH_LONG).show();
    String regex ="((?=.*[0-9])(?=.*[a-z]) (?=.*[A-Z])(?=.*[@#*=])(?=[\\S]+$).{5,10})";
    Matcher matcher = Pattern.compile( regex ).matcher(gettext);
    if (matcher.find())
    {
        result = matcher.group(); 
        Toast.makeText(getApplicationContext(), "Matches",Toast.LENGTH_LONG).show();        
    }
    else
    {
        Toast.makeText(getApplicationContext(), " No Matches",Toast.LENGTH_LONG).show();

    }
}
密码包含一个小写(a-z)、一个大写(a-z)字符、一个特殊字符、一个数字。它必须至少包含8个字符,最多包含14个字符

您应该使用此密码

^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@#*=]).{8,14}$

如果要覆盖ascii中的所有特殊字符,可以使用

[!-/:-@\[-`{-~]

有什么问题吗?您试图匹配的是什么?无效的转义序列(有效的是\b\t\n\f\r\“\'\\)@user2773437您需要转义\d到\\d