javascript - Parse HTML source for dollar amounts then set highest amount as var -


i need javascript function parse html source of page called external script, retrieve dollar amounts in source, , set highest dollar amount javascript variable.

so instance, if page contains text, "your product $40.32 , tax $4.50, total $44.82.", js should parse values , set $44.82 "var total" highest amount. possible?

thanks based on tips wrote this, works. yours or solution others:

var dochtml = document.getelementsbytagname('body')[0].innerhtml;

dochtml = dochtml.replace(/(\r\n|\n|\r)/gm,"");

var price_array = new array; var pattmatch = /(\$(([0-9]{0,1})?.[0-9]{1,2}))|(\$([1-9]{1}[0-9]{0,2}([,][0-9]{3})*)(.[0-9]{1,2})?)/gi; price_array = dochtml.match(pattmatch);

if (price_array) { (var i=0; itotal || !total) { var total=price_array[i]; } }

document.write(total); }


Comments

Popular posts from this blog

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

jQuery clickable div with working mailto link inside -