javascript – Regex is skipping 2nd line

I have the following regex:

/Hero\s+(\d+):\s+Name:\s+(\w+)\s+Lane:\s+(\w+)/g

I am testing it on the following text:

Team A Draft: Hero 1: Name: Pugna Lane: Mid

Hero 2: Name: Faceless Void Lane: Safelane

Hero 3: Name: Earthshaker Lane: Offlane

Hero 4: Name: Lion Lane: Support

Hero 5: Name: Lina Lane: Support

Using the following function in javascript:

    function getHeroMap(text) {
    const heroRegex = /Hero\s+(\d+):\s+Name:\s+(\w+)\s+Lane:\s+(\w+)/g;
    let match;
    const heroes = [];

    while ((match = heroRegex.exec(text)) !== null) {
        const [, position, hero, lane] = match;
        heroes.push({
            position: parseInt(position),
            hero: hero,
            lane: lane.trim()
        });
    }

    return heroes;
}

However it seems to skip the 2nd hero as the result is:

 [
    {
        "position": 1,
        "hero": "Pugna",
        "lane": "Mid"
    },
    {
        "position": 2,
        "hero": "Earthshaker",
        "lane": "Offlane"
    },
    {
        "position": 3,
        "hero": "Rubick",
        "lane": "Support"
    },
    {
        "position": 4,
        "hero": "Juggernaut",
        "lane": "Safe"
    }
]

What have I done wrong?

Read more here: Source link