R.Le Grange R.Le Grange - 1 year ago 94
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.

Answer Source

Try this:


tested on notepad++

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download