简体   繁体   中英

Slice, trim the string from a specific character

var text = ~/Desktop/Bon/ai2html-output/home-pro-Artboard_1.jpg

In js how would I get the final file name. Basically getting any string after the last '/'. It will always change.

You can use this:

var text = '~/Desktop/Bon/ai2html-output/home-pro-Artboard_1.jpg';
var filename = text.replace(/^.*\//, ''); // 'home-pro-Artboard_1.jpg'

Explanation of regex:

  • /^.*\// : greedily remove all leading text up to and including the last slash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM