JS Built-ins
RegExpexecintermediate

RegExp exec() β€” full match

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

exec() returns an array where index 0 is the full match.

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

πŸ’‘ Hints (1)
  • β€’ exec() returns null if no match, or an array where [0] is the full match