0
text = "I have usd **12** only."
var amount = text.match(\(?:USD|usd)\s+.? 
\d+\.?[0-9]{1,2}\); 

it returns

usd *12

I'm trying to grab the number only out of this return?

Is it possible to use "amount" again like this:

amount.match(\\d+\.?[0-9]{1,2}\);
Johny
  • 39
  • 5

1 Answers1

1

You don't need two regexes for this. This regex will do the job on its own:

(?:USD|usd)\s+.*?(\d+(?:\.\d{1,2})?)

It will capture the number in a capture group, so you only need one regex:

"I have usd **12** only."           // -> 12
"I have usd 12.00 only."            // -> 12.00
"I have usd **** 12.00 **** only."  // -> 12.0

regex101 demo

ruohola
  • 21,987
  • 6
  • 62
  • 97