var src = "http://blah.com/SOMETHING.jpg";
src.replace(/.*([A-Z])\.jpg$/g, "X");
at this point, shouldn't src be:
If I use match() with the same regular expression, it says it matched. Regex Coach also shows a match on the character "G".
var src = "http://blah.com/SOMETHING.jpg";
src.replace(/.*([A-Z])\.jpg$/g, "X");
at this point, shouldn't src be:
If I use match() with the same regular expression, it says it matched. Regex Coach also shows a match on the character "G".
Try
src = src.replace(/.*([A-Z])\.jpg$/g, "X");
String#replace isn't a mutator method; it returns a new string with the modification.
EDIT: Separately, I don't think that regexp is exactly what you want. It says "any number of any character" followed by a captured group of one character A-Z followed by ".jpg" at the end of the string. src
becomes simply "X".
The replace function doesn't change src.
I think what you want to do is:
src = src.replace(/.*([A-Z])\.jpg$/g, "X");
src.replace will replace the entire match "http://blah.com/SOMETHING.jpg", not just the part you captured with brackets.