Skip to content

Instantly share code, notes, and snippets.

@sergiogomez
Created July 22, 2009 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sergiogomez/151875 to your computer and use it in GitHub Desktop.
Save sergiogomez/151875 to your computer and use it in GitHub Desktop.
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