1
  for(String paramName:paramNames){
    String regexString = regexPair.get(paramName);
    try{             
        System.out.println(regexString);
        Pattern p = Pattern.compile(regexString);
        Matcher m = p.matcher(paramMap.get(paramName)[0]);
        status = m.matches();
    }catch(Exception e)
    {
        e.printStackTrace();
    }
    if(!status)
           break;
}

where regexSring have value

 "^(?!.*[^A-Za-z0-9@])((?=.*\\d)(?=.*[a-z]).{6,20})$"

The value of regexString is fecthed from mysql db an populated in map and paramMap.get(paramName)[0] have value "dssf55454" but it is retuning false while it should return true.

If I write the following sample program

 Pattern p = Pattern.compile("^(?!.*[^A-Za-z0-9@])((?=.*\\d)(?=.*[a-z]).{6,20})$");
 Matcher m = p.matcher("mal4554SD");
 status = m.matches();
 System.out.println(status);

it returns true. Why?

1 Answer 1

3

The problem might be in the snippet \\d in the regexString.

What is the result printed in console?

System.out.println(regexString);

Also, it will be helpful if you can share more details about regexPair and its get().

Sign up to request clarification or add additional context in comments.

2 Comments

the value of System.out.println(regexString); is ^(?!.*[^A-Za-z0-9@])((?=.*\\d)(?=.*[a-z]).{6,20})$ regexPair contain regex for different field
\\d is the root cause. In your case, regexPair.get() should return \d. I mean you expect some digit number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.