-7

I have a long string in which there is some relevant text that i want to extract and some unwanted html tags. This html tags are not present in all the strings in the array.

For example,

 "description\":\"SOME RELEVANT TEXT...<img width='1' height='1' src='http:\/\/someurl.com.feedsportal.com\/c\/33818\/f\/608449\/s\/1c52b2b5\/mf.gif' border='0'\/><div class='mf-viral'><table border='0'><tr><td valign='middle'><a href=\\\"http:\/\/share.feedsportal.com\/viral\/sendEmail.cfm?lang=en&title=some_title&link=http%3A%2F%2Fwww.someurl.com%2Fworld-newssome_title%2FArticle1-805340.aspx\\\" target=\\\"_blank\\\"><img src=\\\"http:\/\/res3.feedsportal.com\/images\/emailthis2.gif\\\" border=\\\"0\\\" \/><\/a><\/td>"

In the above string, I only want to extract "SOME RELEVANT TEXT..."

amit
  • 10,133
  • 22
  • 72
  • 121
  • 3
    You can only use regular expressions when something is regular. Your example seems to be highly irregular. Also, what did you try to achieve the desired result? No effort on your side, no help on this side. – Sebastian Wramba Feb 01 '12 at 17:47
  • 2
    the `
    ` cannot hold, it is too late.....
    – jAndy Feb 01 '12 at 17:48
  • what about JS: document.getElementById('id of your object').innerHTML = 'new text'; – Nir Alfasi Feb 01 '12 at 17:52
  • Please check this thread. Be sure to read the accepted answer http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Alfabravo Feb 01 '12 at 17:55

2 Answers2

0

This will remove all tags from the text, but not sure if that is what you want.

<script type="text/javascript">   
    var regex = /(<([^>]+)>)/ig;
    var body = "Your text with tags in <br> it<br>";
    var result = body.replace(regex, "");
</script>

Or with jQuery

$('Your text with tags in <br> it<br>').text()
Eystein Bye
  • 5,016
  • 2
  • 20
  • 18
0

PHP or JS?

JS: http://jsfiddle.net/mplungjan/fpzEn/

var str =  "description\":\"SOME RELEVANT TEXT...<img width='1' height='1' src='http:\/\/someurl.com.feedsportal.com\/c\/33818\/f\/608449\/s\/1c52b2b5\/mf.gif' border='0'\/><div class='mf-viral'><table border='0'><tr><td valign='middle'><a href=\\\"http:\/\/share.feedsportal.com\/viral\/sendEmail.cfm?lang=en&title=some_title&link=http%3A%2F%2Fwww.someurl.com%2Fworld-newssome_title%2FArticle1-805340.aspx\\\" target=\\\"_blank\\\"><img src=\\\"http:\/\/res3.feedsportal.com\/images\/emailthis2.gif\\\" border=\\\"0\\\" \/><\/a><\/td>"

alert(str.split(/description":"/)[1].split(/</)[0])
mplungjan
  • 169,008
  • 28
  • 173
  • 236