JS Built-ins
RegExpsourcebeginner

RegExp source β€” alternation

πŸ“– Usage Example
const re = /hello world/i
console.log(re.source) // β†’ 'hello world'

Read RegExp.source to get the pattern text of the regular expression without slashes or flags.

RegExp.prototype.source

The source property works with any pattern including alternation.

Challenge: Verify that /a|b/.source equals 'a|b'.

πŸ’‘ Hints (1)
  • β€’ Alternation operator | is part of the source