"use strict" let myRe = /\s\S+(?=\s)/g; let str = 'exit test some'; myRe.exec(str); let value = myRe.lastIndex; alert(value);
var str = 'exit test some space end', spaces = [], i = -1; do { i++; i = str.indexOf(' ', i); if(i >= 0) spaces.push(i); } while (i >= 0) alert(spaces);