获取第一个.前面的字符串,以及后面的字符串:
const transform = str => {
str.replace(/([^.]*).(.*)/, function($0, $1,$2){
// $0是匹配的完整的字符串
console.log($1,":", $2);
});
}
transform("abc.def.ghi")
// abc:def.ghi
或者
const transform = str => {
str.replace(/(.*)(?:.)(.*)/, function ($0, $1, $2) {
console.log($1, ":", $2);
});
}