1
I have the following URL:
("file:///home/pasta/pasta/img/intro-bg.jpg")
I wonder what regular expression I can use to capture only the intro-bg.jpg
If anyone can help me, I’d appreciate it.
1
I have the following URL:
("file:///home/pasta/pasta/img/intro-bg.jpg")
I wonder what regular expression I can use to capture only the intro-bg.jpg
If anyone can help me, I’d appreciate it.
4
You can use regular expression:
/\/([^/]*)$/
Source: https://stackoverflow.com/questions/19776979/regex-get-all-characters-after-last-slash-in-url
If you want to avoid using Submatches (or Groups), try using this expression: (?!\/)[^\/]+\/?$
that only adds a Negative Lookahead in the regular expression. The demo of the Regex101.
2
Another way:
const str = "file:///home/pasta/pasta/img/intro-bg.jpg";
const basename = str.replace(/^.*\//g, '');
console.log(basename);
To the user who came out distributing downvotes, please leave your comment.
Browser other questions tagged javascript regex
You are not signed in. Login or sign up in order to post.
A
split()
by bar does not resolve? the last element is the image.– rray