javascript - Need regex to replace entire folderpath while preserving file name where last folder could by anything -
this question has answer here:
- how file name full path using javascript? 17 answers
i need regex replace leave file name.
/folder1/folder2/folder3/anything/somefile.html
also show me how implement replace method? replacing entire path match empty string , again leaving file , anything.
thanks in advance.
you can use .*\/
.
.
match anything
*
repeat previous 0 or more times.
\/
literal slash (/
). needs escaped because it's part of regex construct:
var str = '/folder1/folder2/folder3/anything/somefile.html'; str.replace(/.*\//, ''); // "somefile.html"
Comments
Post a Comment