正则小记

正则小记

const r1 = /abc/g  //全局寻找abc
const r2 = /abc/y  //只有abc是相连的才会被匹配到

const str = 'abcabc-abc'

//

console.log(r1.exec(str))
console.log(r1.exec(str))
console.log(r1.exec(str))
//["abc", index: 0, input: "abcabc-abc", groups: undefined]
//["abc", index: 3, input: "abcabc-abc", groups: undefined]
//["abc", index: 7, input: "abcabc-abc", groups: undefined]

console.log(r2.exec(str))
console.log(r2.exec(str))
console.log(r2.exec(str))
//["abc", index: 0, input: "abcabc-abc", groups: undefined]
//["abc", index: 3, input: "abcabc-abc", groups: undefined]

posted on 2019-06-19 22:02  2481  阅读(89)  评论(0编辑  收藏  举报

导航