I want to escape all the special characters in string. Have used the below code.
public static void main(String[] args) { // TODO Auto-generated method
String search = "Helo world!@#$%^&*()";
String regEx = "([^a-zA-Z0-9])";
Pattern escape = Pattern.compile(regEx);
String escapeChar = "\\\\$1";
String value = escape.matcher(search).replaceAll(escapeChar);
System.out.println(value);
}
And i'm getting the below output which is not something have wanted.
output: Helo world\!\@\#\$\%\^\&\*\(\)\
Can someone please help me to correct here.