FabricioG
FabricioG

Reputation: 3320

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.

Upvotes: 0

Views: 123

Answers (1)

Peter Thoeny
Peter Thoeny

Reputation: 7616

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

Upvotes: 2

Related Questions