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 2020å¹´7æ.
dotAll 㯠RegExp ã¤ã³ã¹ã¿ã³ã¹ã®ã¢ã¯ã»ãµã¼ããããã£ã§ãæ£è¦è¡¨ç¾ã§ s ãã©ã°ã使ç¨ããã¦ãããã©ããã示ãã¾ãã
試ãã¦ã¿ã¾ããã
const regex1 = /f.o/s;
console.log(regex1.dotAll);
// äºæ³ãããçµæ: true
const regex2 = /bar/;
console.log(regex2.dotAll);
// äºæ³ãããçµæ: 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
ããã¯äºå®ä¸ãããããä»»æã® UTF-16 ã³ã¼ãåä½ã«ä¸è´ãããã¨ãæå³ãã¾ãããã ãã Unicode åºæ¬å¤è¨èªé¢ (BMP) å¤ã«ããæåãããããã¢ã¹ãã©ã«æåï¼ã¢ã¹ãã©ã«æåã¯ãµãã²ã¼ããã¢ã§è¡¨ããã 1 ã¤ã§ã¯ãªã 2 ã¤ã® . ãã¿ã¼ã³ã§ã®ä¸è´ãå¿
è¦ã¨ãªãã¾ãã
"ð".match(/(.)(.)/s);
// Array(3) [ "ð", "\ud83d", "\ude04" ]
u (unicode) ãã©ã°ã使ç¨ããã¨ãããããã¢ã¹ãã©ã«æåãå䏿åã¨ãã¦ä¸è´ããããã¨ãã§ãã¾ãã
"ð".match(/./su);
// Array [ "ð" ]
ãªãã.* ã®ãããªãã¿ã¼ã³ã¯ãu ãã©ã°ããªãã¦ãããã大ããªã³ã³ããã¹ãã®ä¸é¨ã¨ãã¦ã¢ã¹ãã©ã«æåãæ¶è²»ããè½åãããã¾ãã
"ð".match(/.*/s);
// Array [ "ð" ]
s ãã©ã°ã¨ u ãã©ã°ãä½µç¨ãããã¨ã§ãããããããç´æçãªæ¹æ³ã§ä»»æã® Unicode æåã«ä¸è´ããããã«ãªãã¾ãã
dotAll ã®è¨å®ã¢ã¯ã»ãµã¼ã¯ undefined ã§ãããã®ããããã£ãç´æ¥å¤æ´ãããã¨ã¯ã§ãã¾ããã
ä¾
>dotAll ã®ä½¿ç¨
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® 2027 Language Specification> # sec-get-regexp.prototype.dotAll> |