Remove all dots except the first one from a string

前端 未结 12 2616
栀梦
栀梦 2020-12-15 06:34

Given a string

\'1.2.3.4.5\'

I would like to get this output

\'1.2345\'

(In case there are no dots in the

12条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 06:44

    let str = "12.1223....1322311..";
    
    let finStr = str.replace(/(\d*.)(.*)/, '$1') + str.replace(/(\d*.)(.*)/, '$2').replace(/\./g,'');
    
    console.log(finStr)

提交回复
热议问题