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.

multilineRegExp のアクセサープロパティで、正規表現で m フラグが使用されているかどうかを返します。

試してみましょう

const regex1 = new RegExp("^football");
const regex2 = new RegExp("^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

解説

RegExp.prototype.multiline の値は m フラグが使われていたならば true となり、そうでなければ false になります。m フラグは複数行の入力文字列が複数行として扱われるべきであることを示します。例えば、m フラグが使われた場合、^$ は文字列の全体の先頭と末尾だけに一致する特殊文字から、文字列内のそれぞれの行の先頭と末尾に一致する特殊文字に変化します。

multiline の設定アクセサーは undefined です。このプロパティを直接変更することはできません。

multiline の使用

js
const regex = /foo/m;

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

仕様書

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
multiline
Prototype accessor property (ES2015)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報