我想从一个字符串中去除除了
<span class="match">...text...</span>
以外的所有html内容。例如,如果字符串是"<p>Hello there</p><span class="match">wassup</span>"
我只需要"Hello there<span class="match">wassup</span>"
有人能帮忙吗?我在ruby(rails)中实现。
ActionView::Helpers提供了sanitize
方法来实现这一点。
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize
sanitize "some html", :tags => %w"span"
<p>Hello <!-- </p> --> there</p>
- Bart Kiers