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 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: Tất cả các thuộc tính tĩnh của RegExp hiển thị trạng thái khớp cuối cùng trên toàn cục đều đã bị deprecated. Xem các tính năng RegExp deprecated để biết thêm thông tin.

Thuộc tính accessor tĩnh RegExp.input trả về chuỗi mà regular expression được khớp với. RegExp.$_ là bí danh của thuộc tính này.

Mô tả

input là thuộc tính tĩnh của RegExp, bạn luôn dùng nó như RegExp.input hoặc RegExp.$_, thay vì như thuộc tính của một đối tượng RegExp bạn đã tạo.

Giá trị của input cập nhật mỗi khi một instance RegExp (nhưng không phải subclass của RegExp) tạo ra một khớp thành công. Nếu chưa có khớp nào được thực hiện, input là một chuỗi rỗng. Bạn có thể đặt giá trị của input, nhưng điều này không ảnh hưởng đến các hành vi khác của regex, và giá trị sẽ bị ghi đè lại khi lần khớp thành công tiếp theo xảy ra.

Ví dụ

Sử dụng input và $_

js
const re = /hi/g;
re.test("hi there!");
RegExp.input; // "hi there!"
re.test("foo"); // new test, non-matching
RegExp.$_; // "hi there!"
re.test("hi world!"); // new test, matching
RegExp.$_; // "hi world!"

Thông số kỹ thuật

Specification
Legacy RegExp features
# additional-properties-of-the-regexp-constructor

Tương thích trình duyệt

Xem thêm