[英]One line works but two lines doesn't for regex, why?
I'm using the RegEx practice tool to work on some web scraping.我正在使用 RegEx 练习工具来处理一些网络抓取。
https://extendsclass.com/regex-tester.html https://extendsclass.com/regex-tester.html
(Laboratory Confirmed Cases )([clastexwid\\-.\\"= h<>\\/]+)([0-9]+)/s
This is what I'm searching for. (Laboratory Confirmed Cases )([clastexwid\\-.\\"= h<>\\/]+)([0-9]+)/s
这就是我要找的。
These are what I'm searching.这些是我正在寻找的。
<td class="text-white">Laboratory Confirmed Cases </td>
<td class="text-white">1264450</td>
If I put the text to be searched on the same line, there is a match.如果我将要搜索的文本放在同一行,则匹配。 If not then there is no match.
如果不是,则没有匹配。
Help?帮助?
I'm using Google Apps Script/Javascript.我正在使用 Google Apps 脚本/Javascript。
You need to use \\n?
你需要使用
\\n?
which indicates that there might be a new line.这表明可能有一个新行。
Something like this could work -像这样的东西可以工作 -
Laboratory Confirmed Cases <\\/td>\\n?<td class="text-white">(\\d+)<\\/td>
as seen here -如这里所见 -
https://regex101.com/r/QBDh57/1 https://regex101.com/r/QBDh57/1
this will return the confirmed case numbers.这将返回已确认的病例数。
or depending on if the text is trimmed()
or stripped()
you might need two (\\n?\\n?) of them.或者根据文本是被
trimmed()
还是stripped()
您可能需要其中的两个(\\n?\\n?)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.