R.Le Grange R.Le Grange - 8 months ago 25
HTML Question

How to get float value from string using regex?

I have a string value that will look like this:

"ZAR 200.15"

Using regex, how can I extract the float value to do calculations with?

For some context, I'm using javascript to access an HTML element's value like this:

var amountDueString = document.getElementById("amountDue").innerHTML;

Then I need to use regex to only get the float value.

var amountDue = amountDueString.match(---some regex---);

I want to extract the float value in order to compare it with user input.


Try this:


tested on notepad++