var re = /\d+/g var res while ( (res = re.exec(str)) != null) { ar[i] = res[i]; alert(res[i]); i++; }