我正在使用 RegEx 练习工具来处理一些网页抓取。
https://extendsclass.com/regex-tester.html
(Laboratory Confirmed Cases )([clastexwid\-.\"= h<>\/]+)([0-9]+)/s
这就是我正在寻找的。p>
这些是我正在寻找的。p>
<td class="text-white">Laboratory Confirmed Cases </td>
<td class="text-white">1264450</td>
如果我将要搜索的文本放在同一行,则匹配。如果不是,则不匹配。
帮助?
我使用的是 Google Apps 脚本/Javascript。
答案 0 :(得分:0)
您需要使用 \n?
表示可能换行。
这样的东西可以工作 -
Laboratory Confirmed Cases <\/td>\n?<td class="text-white">(\d+)<\/td>
如这里所见 -
https://regex101.com/r/QBDh57/1
这将返回已确认的病例数。
或者根据文本是 trimmed()
还是 stripped()
,您可能需要其中的两个 (\n?\n?)。