This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const citiesStartingWithB = /B.*?\w+/g | |
const target = "Barcelona Viena Beijing Tokio Bogota"; | |
let result; | |
while ((result = citiesStartingWithB.exec(target)) !== null) { | |
console.log(`Match: ${result[0]}`); | |
console.log(`Last Index at ${citiesStartingWithB.lastIndex}`); | |
} | |
// ✅ Output |