RegExp.prototype.multiline
multiline 訪問器屬性(accessor property)是 RegExp 例項的屬性,用於返回此正則表示式是否使用了 m 標誌。
試一試
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 標誌,則 RegExp.prototype.multiline 的值為 true;否則為 false。m 標誌指示應將多行輸入字串視為多行。例如,如果使用了 m,則 ^ 和 $ 將從僅匹配整個字串的開頭或結尾,變為匹配字串中任何行的開頭或結尾。
multiline 的設定訪問器(set accessor)為 undefined。您無法直接修改此屬性。
示例
使用多行
js
const regex = /^foo/m;
console.log(regex.multiline); // true
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-get-regexp.prototype.multiline |
瀏覽器相容性
載入中…