JS Built-ins
RegExpexecintermediate

RegExp exec() β€” result[0] is 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()

result[0] always holds the full matched string, even with capture groups.

Challenge: Verify that /(\w+)-(\d+)/.exec('hello-42')[0] equals 'hello-42'.

πŸ’‘ Hints (1)
  • β€’ result[0] is always the full matched substring, not just a captured group