D
D
Demigodd2020-04-15 13:24:55
ruby
Demigodd, 2020-04-15 13:24:55

How to shorten a regular expression?

html_content = "<div style=\"padding: 0;\">
  <blockquote><span edit=\"false\">test</span></blockquote>
</div>"

html_content.gsub!("<span edit=\"false\">", '')
html_content.gsub!(/<\/span><\/blockquote>/i, "</blockquote>")
html_content.gsub!(/blockquote>/i, "blockquote>")

# Result
# <div style="padding: 0;">
#   <blockquote>test</blockquote>
# </div>


Link to Repl

The bottom line is to remove spaninside and move blockquoteall the text inside to the parent. spanblockquote

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-04-15
@Demigodd

html_content.gsub!(/<span edit="false">([^<]+)<\/span>/, '\1')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question