JS Built-ins
RegExpsourceintermediate

RegExp source β€” empty 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

An empty RegExp /(?:)/ has a source of '(?:)' to avoid ambiguity with comments.

Challenge: Verify that /(?:)/.source equals '(?:)'.

πŸ’‘ Hints (1)
  • β€’ An empty RegExp literal is represented as /(?:)/ to distinguish from comments