RegExp.prototype.dotAll

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.

dotAllRegExp インスタンスのアクセサープロパティで、正規表現で s フラグが使用されているかどうかを示します。

試してみましょう

const regex1 = new RegExp("foo", "s");

console.log(regex1.dotAll);
// Expected output: true

const regex2 = new RegExp("bar");

console.log(regex2.dotAll);
// Expected output: false

解説

RegExp.prototype.dotAll の値は s フラグが使用されている場合は true、それ以外の場合は false です。s フラグは、ドット特殊文字 (.) が追加で行末記号 ("newline") 文字と一致することを示します。これ以外の場合は一致しません。

  • U+000A LINE FEED (LF) (\n)
  • U+000D CARRIAGE RETURN (CR) (\r)
  • U+2028 LINE SEPARATOR
  • U+2029 PARAGRAPH SEPARATOR

これは事実上、ドットが基本多言語面 (BMP) のすべての文字と一致することを意味します。アストラル文字と一致させるには、u (Unicode) フラグを使用する必要があります。両方のフラグを組み合わせて使用すると、ドットは例外なく任意の Unicode 文字に一致します。

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

dotAll の使用

js
const str1 = "bar\nexample foo example";

const regex1 = /bar.example/s;

console.log(regex1.dotAll); // true

console.log(str1.replace(regex1, "")); // foo example

const str2 = "bar\nexample foo example";

const regex2 = /bar.example/;

console.log(regex2.dotAll); // false

console.log(str2.replace(regex2, ""));
// bar
// example foo example

仕様書

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

ブラウザーの互換性

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
dotAll

Legend

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

Full support
Full support

関連情報