gpt4 book ai didi

javascript - 如何修复 RegEX 模式以找到所有匹配项?

转载 作者:行者123 更新时间:2023-11-29 23:00:58 25 4
gpt4 key购买 nike

我写了正则表达式模式

const PATTERN = /get id\(\) {\s*return '([^']*)'/;

但它会找到第一个匹配项。我添加了 g 标志。

现在不再只获取 ID:53d69076,99969076,22269076来自文字

static get id() {
return '53d69076'
}


static get id() {
return '99969076'
}

static get id() {
return '22269076'
}

我有

 'get id() {\n        return \'53d69076\'',
'get id() {\n return \'99969076\''
'get id() {\n return \'22269076\''

你能帮我修正我的模式吗(只获取 id,而不是完整的 str)?

结果 enter image description here

最佳答案

国际联合会:

/return\s+\'(?<yourCapturedGroup>\w+)\'/

您可以使用名为 yourCapturedGroup 的组使用/g 检索 ID

编辑:这是 regex101 的链接:

https://regex101.com/r/0YQIOh/1

关于javascript - 如何修复 RegEX 模式以找到所有匹配项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55640828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com