Regular expression to capture after the last bar

1

I have the following URL:

("file:///home/pasta/pasta/img/intro-bg.jpg")

I'd like to know what regular expression I can use to catch only intro-bg.jpg

If anyone can help me, thank you.

    
asked by anonymous 25.10.2017 / 20:13

2 answers

4

You can use the regular expression:

/\/([^/]*)$/

Source: link

    
25.10.2017 / 20:19
2

Another way:

const str = "file:///home/pasta/pasta/img/intro-bg.jpg";
const basename = str.replace(/^.*\//g, '');
console.log(basename);
    
25.10.2017 / 20:23