开发者

Regex: finding several linebreaks

hi i'm having this html markup

<body>
<table border="0" width="50%" align="center">
<t开发者_JAVA百科r>
<td>




<center>

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

thx


/(\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"]


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜