Last active
August 29, 2021 14:25
-
-
Save dioxmio/292ae5f45195b66e9ba35bc6ea73c4f4 to your computer and use it in GitHub Desktop.
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 | |
// Match: Barcelona | |
// Last Index at 9 | |
// Match: Beijing | |
// Last Index at 23 | |
// Match: Bogota | |
// Last Index at 36 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment