I heard that there are two persons in the world: Those who know how to regex and those who will never know. I think I'm the type 2 :-/
I have this url:
http://myserver.com/_images/1-102332-2234.jpg?w=800&h=400&c=1
And I need an regex which extracts only the filename 1-102332-2234.jpg
The file ending ca be everything with a . and the parameter "?w=..." is not necessary.
We are trying to get it to work for 2 days now... any help would be appreciated!
try this regex
/[\w-]+\.jpg/g
and to support more file extensions
/[\w-]+\.(jpg|png|txt)/g
var output = "http://myserver.com/_images/1-102332-2234.jpg?w=800&h=400&c=1".match(/[\w-]+\.jpg/g);
console.log(output);
//covering other file extensions
var output = "http://myserver.com/_images/1-102332-2234.jpg?w=800&h=400&c=1".match(/[\w-]+\.(jpg|png|txt)/g);
console.log(output);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With