JS Built-ins
RegExpexecbeginner

RegExp exec() β€” no match returns null

πŸ“– 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 null when there is no match.

Challenge: Verify that /\d+/.exec('abc') returns null.

πŸ’‘ Hints (1)
  • β€’ exec() returns null (not false or undefined) when there is no match