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

Mad*_*han 3 ruby regex

我试图从字符串中删除所有的HTML除外

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

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

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

有人可以帮忙吗?我在红宝石(铁轨)做它

Chr*_*ald 10

ActionView :: Helpers提供了sanitize执行此操作的方法.

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

sanitize "some html", :tags => %w"span"
Run Code Online (Sandbox Code Playgroud)