Reputation: 2673
I've got a file reference in JS and I need to parse it via regex. All as I want is to get the 'C' character that follows a backslash. Does anyone know why this doesn't work?
var str = "C:\Course\folder\file.txt";
str.match(/\\C/g);
If I run this in firebug or similar tool, I get nothing back.
Upvotes: 0
Views: 96
Reputation: 1074266
Does anyone know why this doesn't work?
Because the string you've quoted doesn't contain backslashes. It has an invalid escape sequence (\C
) resulting in just C
and two formfeeds (\f
), but no backslashes.
If you have actual backslashes, it works:
var str = "C:\\Course\\folder\\file.txt";
str.match(/\\C/g);
Upvotes: 4