The following javascript code concatenates the matches found by a regular expression. The regular expression should find any word or set of quoted words. It seems to work perfectly in FireFox and Chrome, but its not working correctly in IE (i have only tested it on IE8).
var searchString = '';
var notString = 'dog cat "pirate ship"';
var matches = notString.match(/(\w+|"[^"]+")/ig);
for (i in matches) {
searchString += " NOT " + matches[i];
}
alert(searchString );
The correct output should be:
NOT dog NOT cat NOT "pirate ship"
but in IE8 im getting:
NOT dog cat "pirate ship" NOT dog NOT cat NOT "pirate ship" NOT 8 NOT 21
Any suggestions on how to make this cross browser compatible.
Many thanks,