gpt4 book ai didi

javascript - 前 n 个匹配项的正则表达式

转载 作者:行者123 更新时间:2023-11-30 20:07:44 48 4
gpt4 key购买 nike

<分区>

我有一个如下的字符串

const str = '_ _  _ _  _ _ _ _'

我如何替换前 2 个 _

例如我需要替换两个_

const newString = '     _ _  _ _ _ _'?

我正在尝试使用 string.replace 和 Regexp。

如何使用正则表达式找到前 n 个特定符号?例如,我需要在下面的字符串中找到 3:

^[_]{3} 

但不是像 ___ 那样只匹配连续的 3 个 _

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