I can’t see where I went wrong here:
var TestString = '+test +"testing multi" -not -"and not this" "w00t" hehe nice +\'test this\' -\'and this as well\'';
var regex = new RegExp('([\\+\\-]{0,1}([\\\'"]).*?\\1|[^\\s]+)', 'g');
var match = regex.exec(TestString);
if (match != null) {
for (var i = 1; i < match.length; i++) {
alert('Match ' + i + ': "' + match[i] + '"');
}
}
For some reason, only +test is matched, followed by an empty match, and that’s it.
Well, this seems to work ok
It wasn’t really on purpose… I just rewrote the RegExp to a literal, because I find that easier to read 🙂
Output