Skip to content

Instantly share code, notes, and snippets.

@AleksandarJeftic
Forked from awesome/strip HTML tags
Created October 18, 2022 15:02
Show Gist options
  • Save AleksandarJeftic/45a08e9b64ae30b0c01ecebc875e5cee to your computer and use it in GitHub Desktop.
Save AleksandarJeftic/45a08e9b64ae30b0c01ecebc875e5cee to your computer and use it in GitHub Desktop.
ruby strip HTML tags
# copied from (thanks!): http://codesnippets.joyent.com/posts/show/615
str = <<HTML_TEXT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>Application error</h1>
<p>Change this error message for exceptions thrown outside of an action (like
in Dispatcher setups or broken Ruby code) in public/500.html</p>
</body>
</html>
HTML_TEXT
puts str.gsub(/<\/?[^>]*>/, "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment