RegExp.prototype.dotAll

RegExp 实例的 dotAll 访问器属性返回此正则表达式是否使用 s 标志。

¥The dotAll accessor property of RegExp instances returns whether or not the s flag is used with this regular expression.

Try it

描述

¥Description

如果使用了 s 标志,则 RegExp.prototype.dotAll 的值为 true;否则,falses 标志指示点特殊字符 (.) 还应与字符串中的以下行终止符 ("newline") 字符匹配,否则将不会匹配:

¥RegExp.prototype.dotAll has the value true if the s flag was used; otherwise, false. The s flag indicates that the dot special character (.) should additionally match the following line terminator ("newline") characters in a string, which it would not match otherwise:

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

这实际上意味着该点将匹配 Unicode 基本多语言平面 (BMP) 上的任何字符。为了允许它匹配星体字符,应使用 u (unicode) 标志。结合使用这两个标志允许点匹配任何 Unicode 字符,没有例外。

¥This effectively means the dot will match any character on the Unicode Basic Multilingual Plane (BMP). To allow it to match astral characters, the u (unicode) flag should be used. Using both flags in conjunction allows the dot to match any Unicode character, without exceptions.

dotAll 的集合访问器是 undefined。你不能直接更改此属性。

¥The set accessor of dotAll is undefined. You cannot change this property directly.

示例

¥Examples

使用点全部

¥Using 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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看