このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
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 2015年7月.
multiline はRegExp のアクセサープロパティで、正規表現でm フラグが使用されているかどうかを返します。
In this article
試してみましょう
const regex1 = /^football/;const regex2 = /^football/m;console.log(regex1.multiline);// 予想される結果: falseconsole.log(regex2.multiline);// 予想される結果: trueconsole.log(regex1.test("rugby\nfootball"));// 予想される結果: falseconsole.log(regex2.test("rugby\nfootball"));// 予想される結果: true解説
RegExp.prototype.multiline の値はm フラグが使われていたならばtrue となり、そうでなければfalse になります。m フラグは複数行の入力文字列が複数行として扱われるべきであることを示します。例えば、m フラグが使われた場合、^ と$ は文字列の全体の先頭と末尾だけに一致する特殊文字から、文字列内のそれぞれの行の先頭と末尾に一致する特殊文字に変化します。
multiline の設定アクセサーはundefined です。このプロパティを直接変更することはできません。
例
>multiline の使用
js
const regex = /^foo/m;console.log(regex.multiline); // true仕様書
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-get-regexp.prototype.multiline> |