View Single Post
  #1 (permalink)  
Old 01-16-2008, 04:45 PM
hamish10101 hamish10101 is offline
Member
 
Join Date: Jan 2008
Posts: 2
hamish10101 is on a distinguished road
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
Reply With Quote
Sponsored Links