I am getting error when try to replace regular expression in java.
for example:
String h = "{hiren:}";
h=h.replaceAll(":}", ":\"\"}");
Please give me solution. Thanks
You need to double-escape some special characters in Pattern
s.
String#replaceAll
takes regular expressions, hence:
String h = "{hiren:}"; h=h.replaceAll(":\\}", ":\"\"}");
Otherwise, you can use String#replace
with no regular expression nor escaping needed.
String h = "{hiren:}"; h=h.replace(":}", ":\"\"}");
It's a commonly mistaken assumption to believe String#replace
will not replace all occurrences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With