且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Javascript中获取两个字符串之间的字符串的正则表达式

更新时间:2022-11-12 09:50:10

前瞻((?= 部分)不消耗任何输入.它是一个零宽度断言(边界检查和lookbehinds也是如此).

A lookahead (that (?= part) does not consume any input. It is a zero-width assertion (as are boundary checks and lookbehinds).

您想要在这里进行常规匹配,以消耗 cow 部分.要捕获两者之间的部分,请使用捕获组(只需将要捕获的模式部分放在括号内):

You want a regular match here, to consume the cow portion. To capture the portion in between, you use a capturing group (just put the portion of pattern you want to capture inside parenthesis):

cow(.*)milk

根本不需要前瞻.