JavaScript RegExp dotAll Property

Beginner
5 min read
Updated: Nov 2026
3 examples
RegExp

Definition

In JavaScript, regex.dotAll is a read-only boolean. It is true when the RegExp was created with the s flag.

By default, the . wildcard matches any character except a newline. With s (dotAll), . also matches newlines, so one pattern can span multiple lines.

Syntax

Create the regex with s, then read .dotAll.

JavaScript
const a = /a.b/;
const b = /a.b/s;
const c = new RegExp("a.b", "s");

console.log(a.dotAll); // false
console.log(b.dotAll); // true
console.log(c.dotAll); // true
CallWhat it does
/a.b/Dot does not match newlines. dotAll is false.
/a.b/sDot can match newlines. dotAll is true.
new RegExp("a.b", "s")Same as the literal with s.

Remember this at a glance:

Remember
 /a.b/.dotAll      → false
 /a.b/s.dotAll     → true

without s:  . skips \n
with s:     . matches \n too

flags are fixed at creation — cannot set .dotAll = true

What You Get

NameDescription
regex.dotAllRead-only. true if the s flag was set when the RegExp was created.
s flagSet at creation with /…/s or new RegExp(pattern, "s").
. wildcardWith s, matches any character including newline.

Return Value

ValueDescription
trueThe RegExp has the s (dotAll) flag.
falseThe RegExp does not have the s flag.

JavaScript Examples

Example 1 — Read dotAll

See how the s flag sets the property.

JavaScript
const a = /a.b/;
const b = /a.b/s;
const c = new RegExp("a.b", "s");

console.log(a.dotAll);
console.log(b.dotAll);
console.log(c.dotAll);
console.log(c.flags);
Try It Yourself

How It Works

  1. Without s, dotAll is false.
  2. With /a.b/s, dotAll is true.
  3. The constructor with "s" does the same.
  4. flags reports "s".

Example 2 — Match across a newline

Compare . with and without s.

JavaScript
const text = "a\nb";

console.log(/a.b/.test(text));
console.log(/a.b/s.test(text));
console.log(/a[\s\S]b/.test(text));
Try It Yourself

How It Works

  1. Without s, . does not cross the newline, so the test is false.
  2. With s, . matches the newline between a and b.
  3. [\s\S] is an older trick that also matches any character including newline.

Example 3 — Capture a multi-line block

Use dotAll to grab text that spans lines.

JavaScript
const re = /START(.*)END/s;
const text = "START\nhello\nworld\nEND";
const m = re.exec(text);

console.log(re.dotAll);
console.log(m[1].trim());
Try It Yourself

How It Works

  1. dotAll is true because of the s flag.
  2. (.*) with s can include newlines between START and END.
  3. trim() removes the outer newlines for a clean print.

Frequently Asked Questions

It is true when the regex was created with the s flag. Then the . wildcard also matches newline characters.
Add s when you create the regex: /pattern/s or new RegExp("pattern", "s").
No. m changes ^ and $. s changes whether . matches newlines. You can combine them: /pattern/ms.
A common pattern was [\s\S] or [\d\D] to match any character including newline.
Modern browsers and Node.js support the s flag. Very old environments may need a polyfill or the [\s\S] workaround.
No. Flags are fixed at creation. Build a new RegExp with s instead.

Next: sticky

Match only from lastIndex with the y flag.

sticky tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful