Using special chars in RegEx causes problems
807605Oct 1 2007 — edited Oct 2 2007Hello Folks,
I have a single string of numbers positive and negative separated by a delimiter. I am trying to convert the negative numbers which are represented by brackets into ones without brakcets e.g. (1.235) to -1.235
Here is what I have in my code
arCols[j].replaceAll("\(", "-");
arCols[j].replaceAll("\)", "");
But that gives a compilation problem as below.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
And if I remove the leading slash that tries to escape the character as below
arCols[j].replaceAll("(", "-");
arCols[j].replaceAll(")", "");
I get the following error.
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed group near index 1
(
How can I replace the brackets using regular expression search and replace?
Thanks for your help.
Sanjay.