-3

Good day. I need to remove all HTML from text. The problem is - some attributes has "<" and ">" symbols in.

I use this rules:

var tmp = html.replace(/(<([^>]+)>)/ig,"") // remove tags
          .replace(/\s/g, "" ); // inline

But its steal has some 0!"> from atributes. Please, see my example on JSFiddle: http://jsfiddle.net/3nn9wmy7/

undefined
  • 98
  • 4

2 Answers2

0

It's not regex so please be gentle: in jQuery

$("*").text(); 

$("*") selects all elements .text() selects the text between tags

http://jsfiddle.net/g9t3bLvz/

I hope you can go further from here

online Thomas
  • 8,864
  • 6
  • 44
  • 85
  • Thanks for unswer, but i need only Regex. I find unser from itsadok. Regex: <(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+> – undefined Nov 12 '15 at 08:04
-3

I find unswer. Author is itsadok (https://stackoverflow.com/users/7581/itsadok)

<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>
Community
  • 1
  • 1
undefined
  • 98
  • 4
  • This would fail with escaped quotes in a string, it would also fail with ``, as well as `<![CDATA[`... it would fail in many scenarios. – Mariano Nov 12 '15 at 08:23