JS Built-ins
RegExpglobalbeginner

RegExp global β€” gi flags

πŸ“– Usage Example
const re = /a/g
console.log(re.global) // β†’ true
const re2 = /a/
console.log(re2.global) // β†’ false

Read RegExp.global to check whether the 'g' flag is set on the regular expression.

RegExp.prototype.global

With both g and i flags, global is still true.

Challenge: Verify that /hello/gi.global equals true.

πŸ’‘ Hints (1)
  • β€’ global checks only for the g flag, regardless of other flags