javascript - data.match(var) not working it seems -
ok have little block of code, supposed scan number on website, reason have hunch it's not scanning @ all.
var regex = /\<span class="currency-robux" data-se="item-privatesale-price">([\d,]+)\<\/span\>/; var priceselling = data.match(regex); priceselling = number(priceselling.replace("," , ""));
is there wrong have on this?
this connected if
statement
if (priceselling <= pricewanting) {
which there calls function run, reason doesn't seem ever run. think regex
wrong not sure how. (pricewanting
has variable; snippet code itself.)
on website, i'm trying extract.
<span class="robux " data-se="item-privatesale-price">115</span>
keep in mind item-privatesale-price
changes, why have set capture data.
you regex fine, using result in wrong way. if matches, homecoming result containing total string, , matched number. not number. need number, match index 1
, can utilize priceselling[1]
.
also in edit matching on span
class="robux "
different regex. if interested in data-se="item-privatesale-price"
can alter match tag attribute within it.
var info = '<span class="robux " data-se="item-privatesale-price">115</span>'; // matches span data-se attribute within // i.e. appears before closing > var regex = /\<span[^>]* data-se="item-privatesale-price"[^>]*>([\d,]+)\<\/span\>/; var priceselling = 0; var pricesellingmatch = data.match(regex); if(pricesellingmatch != null) { priceselling = number(pricesellingmatch[1].replace("," , "")); }
javascript regex
No comments:
Post a Comment