我试图从除
之外的字符串中删除所有html <span class="match">...text...</span>
假设一个字符串是"<p>Hello there</p><span class="match">wassup</span>"
我只需要"Hello there<span class="match">wassup</span>"
有人可以帮忙吗?我在ruby(rails)中做这件事
答案 0 :(得分:10)
ActionView :: Helpers提供sanitize
方法来执行此操作。
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize
sanitize "some html", :tags => %w"span"