public class samppatmatch {
private boolean validatingpswwithpattern(String password){
String math="[a-zA-z0-9]+[(]+(?:[^\\]+|\\.)*";
Pattern pswNamePtrn =Pattern.compile(math);
boolean flag=false;
Matcher mtch = pswNamePtrn.matcher(password);
if(mtch.matches()){
flag= true;
}
return flag;
}
public static void main(String args[]){
samppatmatch obj=new samppatmatch();
boolean b=obj.validatingpswwithpattern("");
System.out.println(b);
}
}
I am getting this type of exception for above code:
java.util.regex.PatternSyntaxException: Unclosed character class near index 28
The expression is invalid.
The closing bracket will be escape because you used
'\\]'
in the expression.solution 1: You can use like
' \\\\] '
.or
solution 2: You can handle the exception to get user friendly message like below,