views:

60

answers:

2

hi i'm having this html markup

<body>
<table border="0" width="50%" align="center">
<tr>
<td>




<center>

and i'm trying to find a "wildcard" for the linebreaks to reach the <center> tag - how would this work?

thx

+2  A: 

The normal RegEx to find a repeating linebreak is "[\r\n]+" which means at least 1 linebreak. This will match any number of linebreaks following directly after each other.

Daniel Bleisteiner
Will not match "empty lines" that have a tab or other spaces on them, and will also match ALL line breaks, not just multiple consecutive lines of them.
gnarf
+3  A: 
/(\s*\n){2,}/

Since some platforms use \r\n as their line-break, and some use only \n this will search for successive strings of whitespace (which \r should also be considered) followed by \n, and ensure to match 2 of them.

Firebug console test:

>>> /(\s*\n){2,}/.exec("<tr>\r\n<td> \r\n \t \r\n \n\n<center>");
[" \r\n \r\n \n\n", "\n"]
gnarf