<script type='text/javascript'>
var str="('apple',16),('orange',7),('banana',12)";
var pattern=/\('([^']+)',([0-9]+)\)/gi;
var reg=new RegExp(pattern);
var arr=str.match(reg);
document.write(arr);
</script>
In the above javascript, I used two pairs of brackets in the pattern to indicate the data I want to get from the string. Obviously, you can see that I want to get the string and the number for every item. I think after the match, I should get an array like this:
arr[0][0] equals to ('apple',16)
arr[0][1] equals to apple
arr[0][2] equals to 16
arr[1][0] equals to ('orange',7)
arr[1][1] equals to orange
arr[1][2] equals to 7
...and so on
but now the arr I get is simply only the full match, like this:
arr[0] equals to ('apple',16)
arr[1] equals to ('orange',7)
...and so on
Why and how I can get back an array containing the data I specified using brackets?