Skip to content

Commit d236427

Browse files
committed
docs(stdlib): fix regex
1 parent cf7c15d commit d236427

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

docs/stdlib/regexp.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ var s = '_x_x';
100100

101101
r.lastIndex = 4;
102102
r.test(s) // false
103+
104+
r.lastIndex // 0
105+
r.test(s)
103106
```
104107

105-
上面代码指定从字符串的第五个位置开始搜索,这个位置是没有字符的,所以返回`false`
108+
上面代码指定从字符串的第五个位置开始搜索,这个位置为空,所以返回`false`。同时,`lastIndex`属性重置为`0`,所以第二次执行`r.test(s)`会返回`true`
106109

107110
注意,带有`g`修饰符时,正则表达式内部会记住上一次的`lastIndex`属性,这时不应该更换所要匹配的字符串,否则会有一些难以察觉的错误。
108111

0 commit comments

Comments
 (0)