Method to remove html escape characters from strings


#1

Is there a convenient way of removing html escape characters from
Strings? I could do using reg exp as in:

=> “hello & goodbye”

“hello & goodbye”.gsub(/&/, “&”)
=> “hello & goodbye”

but I figured there might be a better way.

thx.


#2

Is there a convenient way of removing html escape characters from
Strings? I could do using reg exp as in:

=> “hello & goodbye”

“hello & goodbye”.gsub(/&/, “&”)
=> “hello & goodbye”

but I figured there might be a better way.

require ‘CGI’>> require ‘CGI’
=> true

CGI::unescapeHTML(“hello & goodbye “bar” <baz>”)
=> "hello & goodbye “bar” "


#3

That worked. Thanks!


#4

If found this little snap that I got in my application_helper

def remove_html_tags(str)
str.gsub(/</?[^>]*>/, “”)
end