You're actually dealing with two compilers here - the javac compiler, and the pattern compiler. And both compilers use \ to signal an escape sequence, and \\ to signal a normal \. So the problem is: You start with a String literal: "\\" The javac compiler sees this and interprets it to mean \ The the pattern compiler looks at it, sees a single \, and is confused, because \ needs to have something after it, like \n or \\. So, it gives you an error message. Instead, start with: "\\\\" javac will interpret this as \\ and the pattern compiler will see this as \ which is what you wanted. The rule of thumb is, for every plain literal \ you have in your intended pattern text, put four \'s in the String literal you compile to get the pattern. Yeah, it's weird, but it works.
"I'm not back." - Bill Harding, Twister
posted 14 years ago
thank you,Jim so I'll have to write str.replaceAll("\\\\","\\\\\\\\") something like that
I tested it,like you've said, weird,but it works -eliot
Every man dies, not every man really lives.
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?