Hackerss.com

hackerss
hackerss

Posted on

Java From a string remove characters that are no letters nor numbers nor spaces nor dots nor commas


public class RemoveSpecialCharacters {
    public static void main(String[] args) {
        String str = "Hello, World! How are you?";
        System.out.println(str.replaceAll("[^a-zA-Z0-9\\s.,]", ""));
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)