You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var str = 'asdf123'
var str2 = 'asdf123'
var reg = new RegExp('s','g')
var res = reg.test(str)
reg.lastIndex = 0; // 记录上一次匹配的位置
var res2 = reg.test(str2)
console.log(res);
console.log(res2)
The text was updated successfully, but these errors were encountered:
关于这一点应该写仔细点。
g一般用于exec、match、replace,如果用于test可能会导致问题。
因为g模式会生成一个lastindex参数来存储匹配最后一次的问题,可以设置lastindx为0.
The text was updated successfully, but these errors were encountered: