1

I have this string

<img class="img-thumbnail thumb" style="width:100px;height:100px;" src="data:image/png;base64,/9j/4AAQMCgsOCwkJDRENDgBAQjKv+I1atf2Q==" class="img-thumbnail thumb" style="width:100px;height:100px;"

and I just want to grab data:image/png;base64,/9j/4AAQMCgsOCwkJDRENDgBAQjKv+I1atf2Q==

I've tried multiple attempts on regexr. I'm a bit stuck and so far I have src="(.*)". I'm not sure how to get it to stop at that next quote.

https://regexr.com/53gio

Matt
  • 61
  • 10

3 Answers3

4

You can use DOMParser api

let str = `<img class="img-thumbnail thumb" style="width:100px;height:100px;" src="data:image/png;base64,/9j/4AAQMCgsOCwkJDRENDgBAQjKv+I1atf2Q==" class="img-thumbnail thumb" style="width:100px;height:100px;" />`

let parser = new DOMParser()
let parsed = parser.parseFromString(str, "text/html");

[...parsed.getElementsByTagName('img')].forEach(v=>{
  console.log(v.src)
})
Code Maniac
  • 35,187
  • 4
  • 31
  • 54
1

This works fine for me

src="([^"]*)"
Henrik Albrechtsson
  • 1,653
  • 2
  • 17
  • 17
1

Use the lazy (?) qualifier to grab as few characters as possible and then end on the quote.

src="(.*?)"
Taylor Burke
  • 384
  • 3
  • 13