The matchAll() of a String returns an iterator of results after matching a string against a regular expression.

    
    const sentence = "Apple1Apple2Apple";

    // a pattern having 'Apple' followed by a digit
    const regex = /Apple\d/g;

    // iterator object
    const sentenceMatchAllApple = sentence.matchAll(regex);

    for (match of sentenceMatchAllApple) {
      console.log(match);
    }

    // ["Apple1"]
    // ["Apple2"]