jeudi 13 août 2015

JavaScript subtring method

I need to get a substring from a json. Presently from the JSON, i have extracted the string i need.

I need to check if the variable contains either the word 'refunded' or 'accepted', then this String within square brackets (where the string was found) is to be extracted. The words 'refunded' or 'accepted' if they appear, then they will be within [] along with the rest of the string. The entire string may contain more [] but i need to extract the string immediate within [] containing either or both the string. e.g. the variable is The String is in format as the variable description.

var description="TopSport  $300.00 @ $9.00, [DONALD R2] : 7 [Only $125 was accepted. $175 refunded.]";

Since it contains both accepted/refunded (even either of the word appear the extraction is required), then this is to be taken out of the entire string.

[Only $125 was accepted. $175 refunded.]



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire