JS Built-ins
RegExpexecintermediate

RegExp exec() β€” capture group

πŸ“– 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()

Capture groups are returned in the result array starting at index 1.

Challenge: Verify that /(\d+)/.exec('abc123')[1] equals '123'.

πŸ’‘ Hints (1)
  • β€’ Capture groups in () are available at indices 1, 2, ... in the result array