RegExp.prototype.multiline

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thuộc tính accessor multiline của các instance RegExp trả về liệu cờ m có được sử dụng với biểu thức chính quy này hay không.

Try it

const regex1 = /^football/;
const regex2 = /^football/m;

console.log(regex1.multiline);
// Expected output: false

console.log(regex2.multiline);
// Expected output: true

console.log(regex1.test("rugby\nfootball"));
// Expected output: false

console.log(regex2.test("rugby\nfootball"));
// Expected output: true

Mô tả

RegExp.prototype.multiline có giá trị true nếu cờ m được sử dụng; ngược lại là false. Cờ m chỉ ra rằng một chuỗi đầu vào đa dòng nên được coi là nhiều dòng. Ví dụ, nếu m được sử dụng, ^$ thay đổi từ việc chỉ khớp ở đầu hoặc cuối của toàn bộ chuỗi sang đầu hoặc cuối của bất kỳ dòng nào trong chuỗi.

Accessor set của multilineundefined. Bạn không thể thay đổi thuộc tính này trực tiếp.

Ví dụ

Sử dụng multiline

js
const regex = /^foo/m;

console.log(regex.multiline); // true

Đặc tả kỹ thuật

Specification
ECMAScript® 2027 Language Specification
# sec-get-regexp.prototype.multiline

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

Xem thêm