JS Built-ins
RegExptoStringbeginner

RegExp toString() β€” contains source

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

Use RegExp.toString() to get the string representation of the regular expression including its flags.

RegExp.prototype.toString()

The toString() result contains the source of the pattern.

Challenge: Verify that /\d+/g.toString() contains the source '\d+'.

πŸ’‘ Hints (1)
  • β€’ toString() includes the raw source, including escape sequences