RegExp static properties
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Note: All RegExp static properties that expose the last match state globally are deprecated. See deprecated RegExp features for more information.
The RegExp.input static accessor property returns the string against which a regular expression is matched. RegExp.$_ is an alias for this property.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
javascript.builtins.RegExp.input Deprecated | 1 | 12 | 1 | 3 | 18 | 1 |
| Built-in object | ||||||
RegExp.lastMatch Deprecated The RegExp.lastMatch static accessor property returns the last matched substring. RegExp["$&"] is an alias for this property. | 1 | 12 | 1 | 3 | 18 | 1 |
RegExp.lastParen Deprecated The RegExp.lastParen static accessor property returns the last parenthesized substring match, if any. RegExp["$+"] is an alias for this property. | 1 | 12 | 1 | 3 | 18 | 1 |
RegExp.leftContext Deprecated The RegExp.leftContext static accessor property returns the substring preceding the most recent match. `RegExp["$"]`` is an alias for this property. | 1 | 12 | 1 | 3 | 18 | 1 |
RegExp.n Deprecated The RegExp.$1, …, RegExp.$9 static accessor properties return parenthesized substring matches. | 1 | 12 | 1 | 1 | 18 | 1 |
RegExp.rightContext Deprecated The RegExp.rightContext static accessor property returns the substring following the most recent match. RegExp["$'"] is an alias for this property. | 1 | 12 | 1 | 3 | 18 | 1 |
Syntax
// RegExp static properties example
// See MDN Web Docs for details Live demo
Read capture group shortcuts
Use RegExp.$1 and RegExp.$2 after a successful match.
Inspect match context
Read leftContext, rightContext, and lastMatch after matching text.
Show the last captured input
Demonstrate the legacy static RegExp state shared across matches.
Use cases
-
Regex cleanup
Replace global match-state access with local match objects during refactors.
-
Legacy parsing review
Understand older text-processing code that depends on implicit global capture values.
Cautions
- Global match state is brittle because later regex operations can overwrite the values unexpectedly.
- Local match results make validation and parsing logic far easier to test.
Accessibility
- Reliable parsing helps ensure validation messages and extracted text remain accurate for users.
- Prefer explicit parsing state wherever regex output influences accessible UI.