Regex: match all decimals, but first

Will the regular expression pattern match all decimals, but the first? I am using javascript replace () and would like to remove everything except the first decimal number in a string.

Examples:

1.2.3.4.5 --> 1.2345 .2.3.4.5 --> .2345 1234.. --> 1234. 
+4
source share
1 answer

You can do something like this:

 function parseAndNormalizeDecimal(dec) { var i = 0; var result = dec.replace(/\./g, function(all, match) { return i++===0 ? '.' : ''; }); return result; } 
+8
source

All Articles