Find and replace ( in a String
hi,
Can anyone please help me find and replace character ( in a string.
For example String is abc(xyz
how can i obtain the string abcxyz?
I tried the following code but it doesn work
Pattern pattern = Pattern.compile("(");
Matcher matcher = pattern.matcher("abc(xyz");
String output = matcher.replaceAll("");
I get the error
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed group near index 1
(
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.accept(Unknown Source)
at java.util.regex.Pattern.group0(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at Tester.main(Tester.java:51)
Kindly point out my mistake or suggest an alternative.
Thanks,
Hamish