在Google Spreadsheet Script中,我想捕获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>
之后的所有内容,但它在谷歌电子表格脚本(或我的代码(中不起作用
我期待看到的输出:
Striped Cotton Rugby Short RED
Striped Cotton Polo Short
由于Javascript并不普遍支持lookbehinds,您将不得不接受捕获组:
(i=Transactional>r?n)(?!STYLE)(.*r?n.*)
https://regex101.com/r/ovWA4L/1
您想要的数据将在捕获组#2 中