Skip to content

Instantly share code, notes, and snippets.

@arjunmenon
Forked from awesome/strip HTML tags
Created October 16, 2017 19:13
Show Gist options
  • Save arjunmenon/40dc4ab38d1538eff34a6865984dd551 to your computer and use it in GitHub Desktop.
Save arjunmenon/40dc4ab38d1538eff34a6865984dd551 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