RegExp static properties
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 | |
RegExp.input Deprecated | 1 | 12 | 1 | 3 | 18 | 1 |
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 |
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.