Rahul Patel
Rahul Patel

Reputation: 317

how to extract src from image in javascript while img tag is coming in js object

we have data coming from another application(DB) like below image file has been stored like

@1="< img width=498 height=425 src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ...">"

var data = @1 DownloadCode();

i want to download file image file. I am newbie in JS.

Upvotes: 1

Views: 574

Answers (1)

MMRahman
MMRahman

Reputation: 319

Here how you should do it

var str = '<img width=498 height=425 src="data:image/jpeg;base64,/9j/4AAQSkZJRgA...">';

var regex = /<img.*?src="(.*?)"/;
var src = regex.exec(str)[1];

console.log(src);

Upvotes: 1

Related Questions