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
Asked
Active
Viewed 158 times
1 Answers
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