Reputation: 615
I've tried different way but not working yet.
public String SuEscapeHTML(String text){
text=text.replaceAll("/&/g", "&");
// and how to deal with the double quote? text=text.replaceAll("/"/g", """);
text=text.replaceAll("/'/g", "'");
text=text.replaceAll("/</g", "<");
text=text.replaceAll("/>/g", ">");
text=text.replaceAll("/\\/g", "\");
System.out.println(text);
return text;
}
nothing change by using this function.
So How to make it working?
Upvotes: 0
Views: 363
Reputation: 11032
The syntax of regex you are using is of JavaScript. This is how you will do it in Java
String text = "&>\"<\\'"; //You need to escape " in text also
System.out.println(text.replaceAll("&", "&"));
System.out.println(text.replaceAll("\"", """)); //For quotes
System.out.println(text.replaceAll("'", "'"));
System.out.println(text.replaceAll("<", "<"));
System.out.println(text.replaceAll(">", ">"));
System.out.println(text.replaceAll("\\\\", "\"));
Upvotes: 2