Regular expression for number, commas and points

Asked

Viewed 1,009 times

1

I need to take a specific content of a string that is returned in javascript.

I thought to take his match with regular expression to get exactly the numbers, points and commas of the monetary return that has in part of the text, the problem is that the letters also comes in the return.

For example, I have the phrase "Total Current Estimate: R$ 209.502,84"

I just wanted to get 209,502.84

I arrived so far in

var total = $(".totalEstimadoVigente").html().match("(?:\.|,|[0-9])*").join('');

How to solve this ER?

1 answer

2


Try the following expression: [\d\.\,]+

In your code:

var total = $(".totalEstimadoVigente").html().match(/[\d\.\,]+/g).join('');

The return value with String Total Estimado Vigente: R$ 209.502,84 will be:

209.502,84
  • Regular Expressions do not use quotes for definition. It is necessary to put / at the beginning and end.

  • Beauty, perfectly bro, is perfect

  • 1

    Wouldn’t it be easier to use + instead of {1,} ?

  • @Isac for writing and reading yes, but it still works. As I was doing the tests I forgot this detail.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.