Does anyone know why these two code snippets output different things? The first outputs "tes" which is what I would expect. The second outputs "test" which implies the regular expression doesn't match.
According to the JavaDoc for the String class, these are supposed to be identical. Am I doing something wrong when transposing?
They both work correctly if I remove the $. Then both output "es".
Originally posted by Henry Wong: You are calling the wrong method. You should be calling the replaceAll() method. The replace() method doesn't take a regex.
Henry, A 3 minute response time. Very impressive!
And - doh! I thought "replaceAll". I even looked in the JavaDoc under "replaceAll" to see if it was defaulting to different pattern flags. I've used this method numerous times (correctly.) And yet staring at it - nothing.
subject: regular expression with special character