Entry
How can extract the number for the following value(155) from (AOpen ATX Full Tower (13 Drive Bays) -$155.00)
Aug 25th, 2000 15:44
Martin Honnen, anthony saith,
JavaScript starting from 1.2 has regular expressions for such tasks:
var s = 'AOpen ATX Full Tower (13 Drive Bays) -$155.00';
var pattern = /\$(\d+(\.\d+)?)/
var match = pattern.exec(s);
var n = parseFloat(match[1]);
alert(n);
If you are not sure there is a currency value in the string change that
code above to:
var s = 'AOpen ATX Full Tower (13 Drive Bays) -$155.00';
var pattern = /\$(\d+(\.\d+)?)/
var match = pattern.exec(s);
if (match) {
var n = parseFloat(match[1]);
alert(n);
}