node.js - split url and store in array, object or string using javascript/nodejs -


lets have url such /test-resource/test1-100/test2-200/test3-300

i want split url , store 100, 200 , 300 in array, object or string.

here go

var str = '/test-resource/test1-100/test2-200/test3-300';  var re = /(test\d+)\-(\d+)/g;    var arr = [];    while( res = re.exec(str) ) {    arr[res[1]] = res[2];    alert('match:' + res[0] + ' property:' + res[1] + ' value:' + res[2]);  }    console.log(arr);


Comments