How to Escape Special Characters in Java


In this example we will show the method  to escape special characters in Java.

Source Code

package com.beginner.examples;

import org.apache.commons.lang3.StringEscapeUtils;

public class EscapeSpecialCharacters {

	public static void main(String[] args) {
		
		String s = "test String / /& / ";
		
		s = s.replaceAll("[^u4e00-u9fa5a-zA-Z0-9]", "");
		
		System.out.println(s);

	}

}

Output:

testString
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments