Re: String replaceAll doesn't like commas



On Mon, 30 Jan 2006 20:53:29 -0600, "O.B." <funkjunk@xxxxxxxxxxxxx>
wrote, quoted or indirectly quoted someone who said :

>>>test = test.replaceAll(",", "\\,");
>>
>>
>> Why not just read about it in the documentation?
>>
>> http://download.java.net/jdk6/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)
>
>What's wrong with my regular expression?

\\ is a magic character to regexes and in a magic character to Java
string literals. You have to "quote" it for both. The docs are not
clear unless you read up on Matcher.replaceAll, but he second parm is
a regex too, not just a simple string.

See http://mindprod.com/jgloss/regex.html#QUOTING
http://mindprod.com/regex.html#AWKWARD
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.