javascript - Need regex to replace entire folderpath while preserving file name where last folder could by anything -


this question has answer here:

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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -