简体   繁体   中英

One line works but two lines doesn't for regex, why?

I'm using the RegEx practice tool to work on some web scraping.

https://extendsclass.com/regex-tester.html

(Laboratory Confirmed Cases )([clastexwid\\-.\\"= h<>\\/]+)([0-9]+)/s This is what I'm searching for.

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.

You need to use \\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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM