Originariamente inviato da fcaldera
codice:
var montypython = 'Well, there is egg and bacon; egg sausage and bacon; \
egg and spam; egg bacon and spam; egg bacon sausage and spam; \
spam bacon sausage and spam; spam egg spam spam bacon and spam.';

(function(string, re) {
    var indexesOf = [], i = 0;
    while((match = re.exec(string)) != null) {
        indexesOf[i++] = match.index;
    }
    alert('Occorrenza trovata ' + i + ' volte.');
    if (i > 0) alert('Posizioni : ' + indexesOf );
})(montypython, /spam/ig);
perfetto grazie mille