JS Built-ins
RegExpglobalbeginner

RegExp global β€” no g flag

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

The global property is false when the 'g' flag is not set.

Challenge: Verify that /hi/.global equals false.

πŸ’‘ Hints (1)
  • β€’ Without the g flag, global returns false