JS Built-ins
RegExptoStringbeginner

RegExp toString() β€” basic

πŸ“– 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()

toString() returns the RegExp as a string in '/pattern/flags' format.

Challenge: Verify that /hello/.toString() equals '/hello/'.

πŸ’‘ Hints (1)
  • β€’ toString() wraps the pattern in forward slashes and appends any flags