0

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

Fuxi
  • 7,611
  • 25
  • 93
  • 139
  • 1
    `
    ` cannot hold it is too late http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
    – Amarghosh Dec 01 '09 at 13:46

2 Answers2

3
/(\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
  • 105,192
  • 25
  • 127
  • 161
2

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
  • 3,190
  • 1
  • 33
  • 47
  • 1
    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 Dec 01 '09 at 13:48