Use CGI :: unescapeHTML after performing a regular expression replacement:
CGI::unescapeHTML(str.gsub(/<\/?[^>]*>/,""))
See http://www.ruby-doc.org/core/classes/CGI.html#M000547
In the code snippet above, gsub removes all the HTML tags. Then unescapeHTML () returns all HTML objects (e.g. <, & # 8220) to their actual characters (<, quotes, etc.).
As for the other post on this page, note that you will never pass HTML, for example
<tag attribute="<value>">2 + 3 < 6</tag>
(this is invalid HTML); what you can get instead:
<tag attribute="<value>">2 + 3 < 6</tag>
The gsub call converts the above value to:
2 + 3 < 6
And unescapeHTML will exit:
2 + 3 < 6
vladr source
share