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
  • 59
  • 1
  • 11

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
  • 37,143
  • 5
  • 39
  • 60
1

This works fine for me

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

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

src="(.*?)"
Taylor Burke
  • 424
  • 4
  • 15