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.
Because the string you’ve quoted doesn’t contain backslashes. It has an invalid escape sequence (
\C) resulting in justCand two formfeeds (\f), but no backslashes.If you have actual backslashes, it works: