g for global matching and
i for case-insensitive.
Intuitively, it makes sense for
i to be a property of the constructed RegEx, because the RegEx engine is making a scanner where 'A' and 'a' count as the same token.
I can't come up with a similar argument for the
g flag, however. For example, the following code replaces 'p' characters with 'd' characters (printing "addle"):
Since the RegEx only matches a single 'p', it has to match multiple times to replace all 'p's. Arguably, the RegEx shouldn't "know" that it will be used in this way and the code would be more semantic if it was allowed to be written as this instead:
"apple".replace(/p/, "d", true);