RegExp.prototype.dotAll

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

試してみましょう

解説

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 Language Specification
# sec-get-regexp.prototype.dotAll

ブラウザーの互換性

BCD tables only load in the browser

関連情報