Hi,
The application need to allow only printable characters, blank characters and \n-.
For this purpose I have written the below regular expression.
^(\p{Print}|\p{Blank}|\n-)*$
//****
exam = "this is for
testing purpose message \n only";
regexp ="^(\p{Print}|\p{Blank}|\n-)*$";
public static boolean matchRegExp(final
String exam, final String regexp) {
Pattern p = Pattern.compile(regexp);
Matcher m = p.matcher(exam);
return m.find();
}
//****
I have written this api in a
java file (Test. java) and when I run Test. java as individual program it is working fine and it doesn't allow \n. I am getting the expected output.
But When I am calling the same api in my
struts application, it is not working. It allows \n which is not the expected output.
When I am debugging the code using MyEclipse, in Variable view the message appears as
"this is for testing purpose message \\n only" ; ( via struts application)
"this is for testing purpose message \n only"; (individual program)
I am not sure why individual program is working fine but thru application it's not working.
Please let me know how to handle this "\n". Otherwise do I need to make any change in regular expression?
Thanks,