0

I want to get rid of all symbols or punctuation marks in a string for example String str = "\"hello!.?,\""; the output of str should be: hello

abc123
  • 47
  • 1
  • 6

1 Answers1

0

You can use String's replaceAll.

String str = "\"hello!.?,\"";
String newStr = str.replaceAll("[^\\w]", "");
System.out.println(newStr);

For more details on how to construct a regex, see the documentation of Pattern.

Yoav Gur
  • 1,366
  • 9
  • 15