RegExp.input ($_)
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 thecompatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Note:AllRegExp static properties that expose the last match state globally are deprecated. Seedeprecated RegExp features for more information.
TheRegExp.input static accessor property returns the string against which a regular expression is matched.RegExp.$_ is an alias for this property.
In this article
Description
Becauseinput is a static property ofRegExp, you always use it asRegExp.input orRegExp.$_, rather than as a property of aRegExp object you created.
The value ofinput updates whenever aRegExp (but not aRegExp subclass) instance makes a successful match. If no matches have been made,input is an empty string. You can set the value ofinput, but this does not affect other behaviors of the regex, and the value will be overwritten again when the next successful match is made.
Examples
>Using input and $_
const re = /hi/g;re.test("hi there!");RegExp.input; // "hi there!"re.test("foo"); // new test, non-matchingRegExp.$_; // "hi there!"re.test("hi world!"); // new test, matchingRegExp.$_; // "hi world!"Specifications
| Specification |
|---|
| Legacy RegExp features> # additional-properties-of-the-regexp-constructor> |