Reputation: 687
I want to remove all { } as follow:
String regex = getData.replaceAll("{", "").replaceAll("}", "");
but force close my app with log.
java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX
what have i done wrong ?
Upvotes: 1
Views: 1881
Reputation: 11321
For what you want to do you don't need to use a regex!
You can make use of the replace
method instead to match specific chars, which increases readability a bit:
String regex = getData.replace("{", "").replace("}", "");
Escaping the \\{
just to be able to use replaceAll
works, but doesn't make sense in your case
Upvotes: 0
Reputation: 2556
Curly brackets are used to specify repetition in regex's, therefore you will have to escape them.
Furthermore, you should also consider removing all the brackets in one go, instead of called replaceAll(String, String) twice.
String regex = getData.replaceAll("\\{|\\}", "");
Upvotes: 0
Reputation: 53839
You need to escape {
:
String regex = getData.replaceAll("\\{", "").replaceAll("\\}", "");
Upvotes: 3