I have the following code:
var str = "$123";
var re = /(\$[0-9]+(\.[0-9]{2})?)/;
var found = str.match(re);
alert(found[1]);
alert(found[0]);
I am trying to understand why it found [0] and found [1] will contain $ 123. Why does this happen twice?
I would like to get all the “potential” prices only one, so for example, if I have this line:
var str = "$123 $149 $150"; This will:
found[0] = $123
found[1] = $149
found[2] = $150
And it would be that the array found would not have any more matches.
What's going on here? What am I missing?
source
share