Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Expresiones regulares para borrar saltos de línea en código HTML
# Borramos los párrafos en blanco
text.gsub!(/<p(.)*>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*<\/p>/) { |match| match = ""}
# Luego borramos los divs que se hayan quedado vacíos
text.gsub!(/<div(.)*>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*<\/div>/) { |match| match = ""}
# Y terminamos borrando todo lo que sobra entre etiquetas
text.gsub!(/>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*</) { |match| match = ">\n<"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment