Reputation: 8379
How can I extract the string "XMLFileName" from the below URL using regular expression
var x = "C:\Documents and Settings\Dig\Desktop\XMLFileName.xml"
Thanks
Upvotes: 2
Views: 8519
Reputation: 490143
You could do it with split()
, pop()
and replace()
...
var filename = x.split('\\').pop().replace(/\..+$/, '');
You could also use a single regex...
var filename = x.replace(/.*\\|\..*$/g, '');
Ensure you escape the \
in your string literal too.
Upvotes: 4
Reputation: 8027
You can use: "[^\\]*$
"
but why not using regular javascript functions like indexOf()
etc.
Upvotes: 0