• Skip to main content
  • Skip to search
  • Skip to select language
HTML

Structure of content on the web

  • Web APIs

    Interfaces for building web applications

  • Learn
    • CSS

      Learn to style content using CSS

    • Overview

      A customized MDN experience

    • FAQ

      Frequently asked questions about MDN Plus

  • HTTP Observatory

    Scan a website for free

  • JavaScript
  • global
      • Deutsch
      • Français
      • 日本語
      • 한국어
      • Русский
      • 中文 (简体)

    In this article

    • Try it
    • Description
    • Examples
    • Specifications
    • Browser compatibility
    • See also
    1. escape()
  • Static properties
    1. $1, …, $9 Deprecated
    2. input ($_) Deprecated
    3. lastMatch ($&) Deprecated
    4. lastParen ($+) Deprecated
    5. leftContext ($`) Deprecated
    6. rightContext ($') Deprecated
    7. compile() Deprecated
    8. [Symbol.match]()
    9. [Symbol.split]()
  • Instance properties
    1. global
    2. source
    3. Object/Function
    4. Static methods
      1. toString()
      2. displayName Non-standard
      3. arguments Non-standard Deprecated
      4. caller Non-standard Deprecated
    5. Instance methods
      1. __defineGetter__() Deprecated
      2. __defineSetter__() Deprecated
      3. __lookupGetter__() Deprecated
      4. __lookupSetter__() Deprecated
      5. toLocaleString()
      6. __proto__ Deprecated
      7. RegExp instances returns whether or not the g flag is used with this regular expression.

  • Try it

    const regex1 = /foo/g;
    
    console.log(regex1.global);
    / Expected output: true
    
    const regex2 = /bar/i;
    
    console.log(regex2.global);
    / Expected output: false
    

    Description

    RegExp.prototype.global has the value true if the g flag was used; otherwise, false. The g flag indicates that the regular expression should be tested against all possible matches in a string. Each call to lastIndex property, so that the next call to exec() will start at the next character.

    Some methods, such as [Symbol.replace]() methods (called by String.prototype.replace()) would also have different behaviors when the regex is global.

    The set accessor of global is undefined. You cannot change this property directly.

    Examples

    Using global

    js
    const regex = /foo/g;
    console.log(regex.global); / true
    
    const str = "fooexamplefoo";
    const str1 = str.replace(regex, "");
    console.log(str1); / example
    
    const regex1 = /foo/;
    const str2 = str.replace(regex1, "");
    console.log(str2); / examplefoo
    

    Specifications

    Specification
    ECMAScript® 2026 Language Specification
    # sec-get-regexp.prototype.global

    Browser compatibility

    See also

    • RegExp.prototype.lastIndex
    • RegExp.prototype.dotAll
    • RegExp.prototype.hasIndices
    • RegExp.prototype.ignoreCase
    • RegExp.prototype.multiline
    • RegExp.prototype.source
    • RegExp.prototype.sticky
    • RegExp.prototype.unicode

    Help improve MDN

    RegExp object represents a regular expression, a notation for matching text patterns.","name":"Regular expressions"}},"browserCompat":["javascript.builtins.RegExp.global"],"pageType":"javascript-instance-accessor-property"}}

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant