正则表达式匹配 Google 电子表格中特定单词后的前 n 行

regex to match first n lines after a specific word in Google Spreadsheet

在 Google 电子表格脚本中,我想捕获 i=Transactional> 之后的前两行 新行不应以 STYLE

开头

全文如下:

<http://link.ORDERACK...&i=Transactional>
STYLE: 0043
QTY: 11 

<http://link.ORDERACK...&i=Transactional>
Striped
Cotton Rugby Short RED
<http://link.ORDERACK...&i=Transactional>
STYLE: 0042
QTY: 10 

<http://link.ORDERACK...&i=Transactional>
Striped
Cotton Polo Short

正则表达式应忽略以 STYLE

开头的行

我使用了这个正则表达式:

var regExp=new RegExp("((i=Transactional\>\r*\n)(?!STYLE)(.*\r*\n){2})","gm");
m = regExp.exec(text)

但是,输出还包括 i=Transactional>

i=Transactional> Striped Cotton Rugby Short RED
i=Transactional> Striped Cotton Polo Short

尝试使用 (?<=i=Transactional\> 获取 i=Transactional> 之后的所有内容,但它在 google 电子表格脚本(或我的代码)中不起作用

我期望看到的输出:

Striped Cotton Rugby Short RED
Striped Cotton Polo Short

由于 Javascript 并不普遍支持后视,您将不得不接受捕获组:

(i=Transactional>\r?\n)(?!STYLE)(.*\r?\n.*)

https://regex101.com/r/ovWA4L/1

您需要的数据将在捕获组 #2 中