Lodash isRegExp and Regex Flags Across Realms

The Lodash utility method _.isRegExp reliably identifies standard JavaScript regular expressions across different execution realms (such as iframes or popups) regardless of which regular expression flags are configured. Because Lodash relies on internal object tagging rather than prototype inheritance checks, all modern ECMAScript regular expression flags—including g, i, m, s, u, y, d, and v—are successfully recognized without causing identity mismatch issues.

Cross-Realm Regular Expression Identification

In browser environments, a script often interacts with objects created in different execution contexts, such as an iframe or another window. When a regular expression is created in an iframe and passed to the host window, using instanceof RegExp evaluates to false because the iframe's RegExp.prototype does not match the host's RegExp.prototype.

Lodash resolves this cross-realm boundary issue by using baseGetTag or Object.prototype.toString.call(value). Regardless of the realm in which an object was instantiated, a native regular expression returns the internal tag [object RegExp].

Supported Regular Expression Flags

Flags alter matching behavior and syntax rules, but they do not alter the underlying object type. Consequently, _.isRegExp successfully identifies any regular expression containing any combination of the following ECMAScript flags across realms:

Because regular expression flags simply update internal internal slots (such as [[OriginalFlags]]) without changing the internal [[Class]] or [Symbol.toStringTag] to anything other than RegExp, no combination of flags will cause _.isRegExp to fail across browser realms.