首页 > Web开发 > 详细

JS 正则表达式转换字符串

时间:2019-09-21 14:22:07      阅读:116      评论:0      收藏:0      [点我收藏+]

获取第一个.前面的字符串,以及后面的字符串:

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);
  });
}

JS 正则表达式转换字符串

原文:https://www.cnblogs.com/flipped/p/11562214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!