就一点正则用法
来源:7-5 最大矩阵-代码实操(2)

_玲
2019-03-10
能想到的问题,都被老师补全了。
不开森…
// 把二位数组重新表达,把相邻的1提取出来(起始点+截止点)
arr = arr.map(item => {
let str = item.join('')
let r = reg.exec(str)
let rs = []
while (r) {
// 这里可以用reg.lastIndex - 1 === r.index + r[0].length - 1
rs.push([r.index, r.index + r[0].length - 1])
r = reg.exec(str)
}
return rs
})
reg.lastIndex:The index at which to start the next match. If g is absent, this will always be 0.
写回答
1回答
-
快乐动起来呀
2019-03-10
哈哈,你已经很不错了,真的是用心在学习,等我的奖励吧
112019-03-10
相似问题