How to get just one number and not two before dot with regex?

Viewed 39

I am trying to get the number 1.039,08180600 with regex but there is numbers like 15.623,77056789 in the string.

I used ([0-9]?)(\.?)([0-9]{3},[0-9]{8}) to get the x.xxx,xxxxxxxx.

Is there a way to do it? And is there a better way to write the regex I am using?

2 Answers

A general pattern which might work for you is:

\b\d\.\d+,\d+\b

use \b or word boundary, the regex \b\d\.\d{3},\d{8}\b

var number = '1.039,08180600 15.623,77056789 2.039,08100 7.039,08180677'
console.log(number.match(/\b\d\.\d{3},\d{8}\b/g))

Related