我是regex的新手,有一个返回text
的cdn url,我想用javascript来匹配和提取版本号。我可以匹配latestVersion,但我不知道如何得到它里面的值。text
上的交货日期:
...oldVersion:"1.2.0",stagingVersion:"1.2.1",latestVersion:"1.3.0",authVersion:"2.2.2"...
我尝试执行此行以显示latestVersion:"1.3.0
,但不成功
const regex = /\blatestVersion:"*"\b/
stringIneed = text.match(regex)
我只需要1.3.0
,不包括字符串latestVersion:
3条答案
按热度按时间kzipqqlq1#
您可以使用lookbehind或撷取群组,如下所示:
v2g6jxz62#
尝试添加捕获组
()
以匹配Regex中的某些字符串。olqngx593#
有很多方法可以做到这一点。这是一个:
.*?
是一个“非贪婪”通配符,它将匹配尽可能少的字符,以便匹配整个正则表达式。因此,它将在"
之前停止匹配。