正则表达式:找到几个换行符

发布于 2024-08-13 15:25:09 字数 253 浏览 9 评论 0原文

您好,我有这个 html 标记

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




<center>

,我正在尝试为换行符找到一个“通配符”以到达

标记 - 这将如何工作?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自演自醉 2024-08-20 15:25:09
/(\s*\n){2,}/

由于某些平台使用 \r\n 作为换行符,而有些平台仅使用 \n 这将搜索
连续的空格字符串(也应该考虑 \r),后跟 \n,并确保匹配其中的 2 个。

Firebug 控制台测试:

>>> /(\s*\n){2,}/.exec("<tr>\r\n<td> \r\n \t \r\n \n\n<center>");
[" \r\n \r\n \n\n", "\n"]
/(\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"]
单挑你×的.吻 2024-08-20 15:25:09

查找重复换行符的正常正则表达式是“[\r\n]+”,这意味着至少有 1 个换行符。这将匹配任意数量的紧随其后的换行符。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文