If you want a quick fix, try:
code:
var MyString = "C:\\David\\eg.png";
var re = /([^\/\\]*)\./;
var FileBase = re.exec(MyString)[1];
But just as an explanation, when you use the
new RegExp("...") notation, your regular expression is taken from what it appears as a string. That means
new RegExp("\\\\a\\\\") works the same as
/\\a\\/, both of which capture a string which displays as
\a\. My regular expression captures a group of letters that are not slashes up to a full-stop. Be aware that if there are no matches though, your script will have an error.