gpt4 book ai didi

javascript - 正则表达式模式中的可选子字符串

转载 作者:行者123 更新时间:2023-11-28 14:09:51 25 4
gpt4 key购买 nike

我有一个字符串 Failed to acquire capacity on the hall有时我也可能会得到 Failed to acquire new capacity on the hall 。因此,为了涵盖这两种情况,我想做 new作为可选。

所以我将 new 与 ? 分组如(new)?如下所示的模式

模式:failed to acquire (new)? capacity

但它没有按预期工作,即匹配 Failed to acquire capacity on the hall即使new是否存在。引用:https://regex101.com/r/2YhjKc/1

我在这里犯了什么错误?

谢谢。

最佳答案

单词new也被空格包围,您也应该考虑到这一点,例如

failed to acquire\s+(new\s+)?capacity

Demo

关于javascript - 正则表达式模式中的可选子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59978693/

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