...text.....">

Regular expression to remove all html tags except span tag

I am trying to remove all html from a string except

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

Assume the line "<p>Hello there</p><span class="match">wassup</span>"

I just need "Hello there<span class="match">wassup</span>"

Can anyone help? I do it in ruby ​​(rails)

+3
source share
1 answer

ActionView :: Helpers provide a method sanitizefor this.

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

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

Source: https://habr.com/ru/post/1776942/


All Articles