I'm trying to select all non whitespace characters. But regular expression \S*
or [^\s]*
failing with "JavaScript heap out of memory" error for any string.
I tried it with node and directly on browser console. However when I tried it with an online regex tester then it worked fine.
var validAttrStrRegxp = new RegExp("\\S*", "g");
getAllMatches("any string",validAttrStrRegxp);
var getAllMatches = function(string, regex) {
var matches = [];
var match = regex.exec(string);
while (match) {
var allmatches = [];
for (var index = 0; index < match.length; index++) {
allmatches.push(match[index]);
}
matches.push(allmatches);
match = regex.exec(string);
}
return matches;
};