正则表达式去除除span标记之外的所有html标记

时间:2010-11-25 18:29:02

标签: ruby regex

我试图从除

之外的字符串中删除所有html

<span class="match">...text...</span>

假设一个字符串是"<p>Hello there</p><span class="match">wassup</span>"

我只需要"Hello there<span class="match">wassup</span>"

有人可以帮忙吗?我在ruby(rails)中做这件事

1 个答案:

答案 0 :(得分:10)

ActionView :: Helpers提供sanitize方法来执行此操作。

http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize

sanitize "some html", :tags => %w"span"