I have url and img tag like these (files can have gif, png or jpg extension):
'C:\fakepath\Chrysanthemum.jpg'
'<img src="http://localhost/rootil/uploads/arrow.jpg">'
and I want to parse filenames from them, so I get
'Chrysanthemum.jpg'
'arrow.jpg'
respectively.
My first try is:
alert(g.slaves[f].value.match(/\.\w{1,4}$/gi))
but it gives me only .jpg
.
Can someone help me with correct regexp for that situation?
I think that should work for you:
var r = /[^/\\]+(?:jpg|gif|png)/gi;
var s = 'C:\\fakepath\\Chrysanthemum.jpg \
<img src="http://localhost/rootil/uploads/arrow.jpg">';
s.match(r);
// => ["Chrysanthemum.jpg", "arrow.jpg"]
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