JavaScript Regex Only returns one match -
i can't see went wrong here:
var teststring = '+test +"testing multi" -not -"and not this" "w00t" hehe nice +\'test this\' -\'and well\''; var regex = new regexp('([\\+\\-]{0,1}([\\\'"]).*?\\1|[^\\s]+)', 'g'); var match = regex.exec(teststring); if (match != null) { (var = 1; < match.length; i++) { alert('match ' + + ': "' + match[i] + '"'); } }
for reason, +test matched, followed empty match, , that's it.
well, seems work ok
var teststring = '+test +"testing multi" -not -"and not this" "w00t" hehe nice +\'test this\' -\'and well\''; var match = teststring.match(/([+-]?([\\'"]).*?\2|[^\s]+)/gi) if (match != null) { (var = 1; < match.length; i++) { alert('match ' + + ': "' + match[i] + '"'); } }
it wasn't on purpose... rewrote regexp literal, because find easier read :)
output
match 1: "+"testing multi"" match 2: "-not" match 3: "-"and not this"" match 4: ""w00t"" match 5: "hehe" match 6: "nice" match 7: "+'test this'" match 8: "-'and well'"
Comments
Post a Comment