JS Built-ins
RegExpsourcebeginner

RegExp source β€” basic pattern

πŸ“– 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 returns the text of the pattern without the surrounding slashes or any flags.

Challenge: Verify that /hello/.source equals 'hello'.

πŸ’‘ Hints (1)
  • β€’ source returns only the pattern text, not the slashes or flags