[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug classpath/26112] string.replaceAll("\\")
From: |
mark at gcc dot gnu dot org |
Subject: |
[Bug classpath/26112] string.replaceAll("\\") |
Date: |
6 Feb 2006 14:07:18 -0000 |
------- Comment #1 from mark at gcc dot gnu dot org 2006-02-06 14:07 -------
Confirmed. replaceAll can be use groupbackreferences through $1-$9 and this
actually works. See Matcher.appendReplacement() and REMatcher.substituteInto().
But we don't properly handle escaping using backslash \.
Here is a small example:
public class ReplaceAll
{
public static void main(String[] args) throws Exception
{
String s = "some.dotted.text ending in a dot.";
s = s.replaceAll("\\.", "\\\\.");
System.out.println(s);
s = "Start by saying 'Hello Mark'";
s = s.replaceAll("Hello (\\w+)",
"Welcome $1, do you want anything to drink, $1?");
System.out.println(s);
s = "All dollars are written as $";
s = s.replaceAll("$", "\\$ (the dollar-sign)");
System.out.println(s);
}
}
We only handle the second replace correctly.
--
mark at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mark at gcc dot gnu dot org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2006-02-06 14:07:18
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26112