Home > Mobile >  Regex to get the right most number after $
Regex to get the right most number after $

Time:03-26

I have the following string and I am trying to get the right most numbers from them.

Input:

-30%$13.99$19.99
$19.99

Output:

$19.99
$19.99

What is the best way for me to do this with regex?

Here is what I have so far:

[\$ ] ?(\d ([,\.\d] )?)

CodePudding user response:

/\$[0-9] (\.[0-9] )?$/mg
/\$\d (\.\d )?$/mg

Tested with ECMAScript (JavaScript) and PCRE2 (PHP >=7.3) on the string that you provided

  • [0-9] (\.[0-9] )? stands for float or integer numbers.
  • The last $ stands for the end of the line.
  • Related