I have one problem when i am using following code snippet
String regexString=regexPair.get(paramName);
Pattern p = Pattern.compile(regexString);
Matcher m = p.matcher(paramMap.get(paramName)[0]);
status = m.matches();
it return false
where regexPair is hashmap and regexPair.get(paramName) is
"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"
while I will ureplace
String regexString="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"
then it works fine
paramMap.get(paramName)[0] return agsd@gmail.com.
I am not getting why this is occurring please help me.
How do you know that
regexPair.get(paramName)is the string you’ve given? Is that the result of someprintlncall?I suspect the quoting is not entirely the same. It may be that
regexPair.get(paramName)actually contains'\\'followed by another'\\'(that is, two real backslashes in succession), while the replacement only contains"\\"(which is a single backslash). Note that the string"(\\."is really only 3 characters long.