0

I have a string

eg: "Brown fox image  <img src="http://imageurl.com/image.png" alt="Some Text"> some text"

How to get "src" value using regular expressions.

Answer:

getImage(content) {
    var myRegexp = new RegExp(/<img.*?src="(.*?)"/);
    var match = myRegexp.exec(content);
    if (match)
      return match[1];
  }
4
  • Don't. Parse the string to DOM elements and access the src property of the img element. Commented Dec 28, 2016 at 21:55
  • what is the origin of that string? Text content or a part of javascript code? Commented Dec 28, 2016 at 21:56
  • Someone post that question, you know the one Commented Dec 28, 2016 at 21:56
  • 1
    @OlivierGrech stackoverflow.com/q/1732348/218196 Commented Dec 28, 2016 at 22:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.