gpt4 book ai didi

javascript - 使用变量时如何防止正则表达式测试切换?

转载 作者:行者123 更新时间:2023-11-30 12:34:09 25 4
gpt4 key购买 nike

<分区>

我刚刚注意到以下奇怪行为(在浏览器和 中:

> a = /^\/foo/g
/^\/foo/g
> a.test("/foo")
true
> a.test("/foo")
false
> a.test("/foo")
true
> a.test("/foo")
false
> a.test("/foo")
true

我们这里有什么样的疯狂科学?我怎样才能防止这种行为?

我只想有一个正则表达式变量来检查字符串是否与全局模式匹配。


Documentation pages似乎没有给那里带来一些光明……我真的很感激指向文档引用的链接。

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