JS Built-ins
RegExptoStringbeginner

RegExp toString() β€” includes slashes

πŸ“– 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 result of toString() includes the surrounding forward slashes.

Challenge: Verify that /test/.toString() includes two '/' characters.

πŸ’‘ Hints (1)
  • β€’ toString() always surrounds the pattern with forward slashes