1const str = 'my name is mark, my age is 18, my sex is male'
2var reg = /is/
3
4// 非全局
5reg.exec(str) // ["is", index: 8, input: "my name is mark, my age is 18, my sex is male", groups: undefined]
6
7// 全局
8var reg = /is/g
9reg.lastIndex // 0
10reg.exec(str) // ["is", index: 8, input: "my name is mark, my age is 18, my sex is male", groups: undefined]
11reg.lastIndex // 10
12
13reg.exec(str) // ["is", index: 24, input: "my name is mark, my age is 18, my sex is male", groups: undefined]
14reg.lastIndex // 26
15
16reg.exec(str) // ["is", index: 38, input: "my name is mark, my age is 18, my sex is male", groups: undefined]
17reg.lastIndex // 40
18
19reg.exec(str) // null
20reg.lastIndex // 0