There is a string that can be of this type.

100.15.98 

And maybe this

 940.56 

It seems like str.match (reg) should fit with the g flag, but not how can I figure out how to apply it.

At the output, you need something if the string has 2 points, then replase ('.', '') (First entry), and if there is 1 point, do not touch it.

    1 answer 1

    it's not clear why you want / g, just "look ahead (? =)" is there a second point

     console.log (fix('100.15.98'), fix('100.15.98.11'), fix('940.56')); console.log (fixGlobal('100.15.98 940.56 100.15.98.11')); function fix(num = '') { return String(num).replace(/^(\d+)\.(?=\d+\.\d+)/, '$1,'); } //если искать надо в большом тексте, то /g конечно пригодится function fixGlobal(num = '') { return String(num).replace(/(^|\D)(\d+)\.(?=\d+\.\d+)/g, '$1$2,'); } 

    • I apologize for the intrusiveness, and if you need to leave only the last point in the line, and replace all the rest? - Evgeny Gusev
    • In the first example, remove the check of the beginning of the line, put / g - zb '
    • thanks a lot - Evgeny Gusev