-3

So there's some html as string like:

     3.399<sup>99</sup> <span>Dineros</span> bla bla

or even

     3,399<sup>99</sup> <span>Dollars</span> bla bla

and I need some regex that applied to this string would give:

["3399", "99"]

so that I can eventually get a Number from the integer and decimal part

Andrei Roba
  • 2,156
  • 2
  • 16
  • 33

1 Answers1

1

Use String#match method to fetch the strings and using Array#map method generate the number array by replacing the dot or comma.

var str = '3.399<sup>99</sup> <span>Dineros</span> bla bla';

console.log(
  str
  // get the pattern matching substrings
  .match(/\d+(?:[.,]\d+)?/g)
  // iterate and generate the Number
  .map(function(d) {
    // parse the generated string
    return Number(
      // replace the dot or comma
      d.replace(/[.,]/, '')
    )
  })
)
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188