I’m trying to get the first image tag on a page. The regular expression below works on Chrome and Opera but not on Firefox.
var ex = /<img src=".+">/;
I only got the image tags which doesn’t have the closing tags /> so this works.
This is the string that I’ll use it on:
var str = 'dd<div><img src="http://img.png" alt="" align="none"></div><div>ddd</div>'
Executing returns null in Firefox:
ex.exec(str)
But in Chrome and Opera it returns an array. In which I just have to use [0] to get the image tag.
Any ideas? Seems like Firefox doesn’t like my regex.
I only need the first match that’s why I’m not using the g option.
This will do