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.
multiline
は RegExp
のアクセサープロパティで、正規表現で 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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
multiline | ||||||||||||||
Prototype accessor property (ES2015) |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.