Expresiones regulares para borrar saltos de línea en código HTML


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # Borramos los párrafos en blanco
  2. text.gsub!(/<p(.)*>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*<\/p>/) { |match| match = ""}
  3. # Luego borramos los divs que se hayan quedado vacíos
  4. text.gsub!(/<div(.)*>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*<\/div>/) { |match| match = ""}
  5. # Y terminamos borrando todo lo que sobra entre etiquetas
  6. text.gsub!(/>(\s)*(<br(\s)*(\/)*>)*(\s)*(&nbsp;)*</) { |match| match = ">\n<"}

URL: http://gist.github.com/151875

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.