0

I'm struggling to seperate image from text. I converted rss feed to json, because its easier to work whit, but I don't know how to split string or seperate image form text.

JSON: "description": "<img src=\"https://files.facepunch.com/s/cd60c1258ac2.jpg\"><br/>Raids, bases, mods, and more.",

Trying to get only <img src=\"https://files.facepunch.com/s/cd60c1258ac2.jpg\">

I'm begginer and started learning javascript recently, but can't figure out how if is even possible to split this.

https://jsfiddle.net/4szqst2m/

1 Answers1

0

Of course depending on the text you pass this how you do it using regex:

var json = " \"description\": \"<img src=\"https://files.facepunch.com/s/cd60c1258ac2.jpg\"><br/>Raids, bases, mods, and more.";

var rex = /(<img[^>]+src="?[^"\s]+"?\s*\/?>)/g;

var imgTag = ''; 
var m = '';

while (m = rex.exec(json) ) {
    imgTag = m[1];
}

alert(imgTag);

Take a look at this answer too

Dabbas
  • 3,112
  • 7
  • 42
  • 75