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
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
Share Improve this question asked Dec 8, 2011 at 5:27 ExceptionException 8,38924 gold badges88 silver badges141 bronze badges 02 Answers
Reset to default 4You could do it with split()
, pop()
and replace()
...
var filename = x.split('\\').pop().replace(/\..+$/, '');
jsFiddle.
You could also use a single regex...
var filename = x.replace(/.*\\|\..*$/g, '');
jsFiddle.
Ensure you escape the \
in your string literal too.
You can use: "[^\\]*$
"
but why not using regular javascript functions like indexOf()
etc.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744895490a4599670.html
评论列表(0条)