标签:open push style ++ nbsp sda close sed abd
1、正则截取两个字符串间的值
let str="sdfsdf:12545.sdafs.dfsdf:98794564.sdfdf:"; let getStr = str => { let reg = /:(.+?)\./g; let arr = str.match(reg); let newArr =[] for (let i =0;i<arr.length;i++) { newArr.push(arr[i].replace(/(:|\.)/g, ‘‘)) } return newArr; } console.log(getStr(str)) // ["12545", "98794564"]
优化后
let str="sdfsdf:12545.sdafs.dfsdf:98794564.sdfdf:"; let getStr = str => { let reg = /:(.+?)\./g; let arr = str.match(reg); return arr.join(‘,‘).replace(/(:|\.)/g, ‘‘); } console.log(getStr(str))
标签:open push style ++ nbsp sda close sed abd
原文地址:http://www.cnblogs.com/vhen/p/7865275.html