-1

I have strings like " $250.00", " $100.00" , " $1000.88", " $75.00" and I would like to get just the numbers with the period in the middle. i.e.: "250.00" "100.00" "1000.88" "75.00"

Also, the $ could be another currency. Not necessarily $. So, I just need to get numbers and period.

I tried with some regular expressions that I know but couldn't do it.

var initialPrice = " $250.00" // I need just 250.00

I need to get rid of the spaces if possible. I just need the numbers and the period.

Thanks!!!!

dragon25
  • 33
  • 5
  • It's not a duplicate. I need the period too. – dragon25 Jul 12 '19 at 14:59
  • It's easy to add period after you have the `int` value. Choose whatever is best suited for your needs! I just posted the link here cuz it might help other ppl. – rafaelcastrocouto Jul 12 '19 at 15:01
  • It's a simple thing. If you don't have spaces between, its just `[\d.]+`. If you have spaces, replace all whitespace with blank first. It's easier that you don't have to validate the form. –  Jul 12 '19 at 15:11

1 Answers1

0
(?:\d+\.\d+)
  1. Find 1 or more integers until you find a period
  2. match the period
  3. match 1 or more digits after the period

This is a demo

This is how you might want to do this in javascript.

var initialPrice = " $250.00" // I need just 250.00
var v = initialPrice.match(/(?:\d+\.\d+)/)[0];
console.log(v);
Aelphaeis
  • 2,593
  • 3
  • 24
  • 42