Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex to get the right most number after $

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$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]+)?)

>Solution :

/\$[0-9]*(\.[0-9]*)?$/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.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading