JS Built-ins
RegExptoStringbeginner

RegExp toString() β€” with flags

πŸ“– 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() includes flags at the end.

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

πŸ’‘ Hints (1)
  • β€’ toString() appends flags after the closing slash