JS Built-ins
RegExpexecintermediate

RegExp exec() β€” index property

πŸ“– Usage Example
const re = /(\d+)/
const match = re.exec('Price: 42')
console.log(match[0]) // β†’ '42'
console.log(match[1]) // β†’ '42'

Use RegExp.exec() to search for a match and return detailed match information.

RegExp.prototype.exec()

The result array has an index property indicating where the match starts.

Challenge: Verify that /\d+/.exec('abc123').index equals 3.

πŸ’‘ Hints (1)
  • β€’ The index property tells you where in the string the match was found