Regex Dot Does Not Match Newline – Use the JavaScript s Flag

Local only

Fix a valid regex whose dot wildcard stops at a newline and therefore misses text spanning multiple lines.

9 chars · 2 lines

8 chars · 1 line

Pattern did not match the inputFlags: g

Regex dotAll behavior

How to make regex dot match a newline

In JavaScript, . does not normally match line terminators. A valid pattern such as start.*end therefore misses when start and end are on different lines. Enable the s flag when the wildcard is intended to span newlines. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Valid regex behavior check
  • DotAll comparison
  • JavaScript s flag
  • Match or No match output
  • Newline debugging
  • Browser-local processing

Steps

  1. Confirm that the target text crosses a newline between the tokens around . or .*.
  2. Add s once to the Flags field when dot should include line terminators.
  3. Retest both single-line and multiline samples so dotAll does not broaden the pattern more than intended.

s changes dot; m changes anchors

The s flag is commonly called dotAll because it lets . include line terminators. The m flag is different: it changes ^ and $ so they can operate at line boundaries.

DotAll regex example

Keep the same wildcard pattern and enable s to cross the newline.

Pattern and flags

start.*end / no flags

Corrected flags

s

Common questions

Frequently asked questions

Why does .* stop before a newline?

Without s, JavaScript's dot wildcard excludes line terminators.

Will m fix dot across newlines?

No. m affects ^ and $, not the dot wildcard.

Can I avoid s by changing the pattern?

Yes. Patterns such as [\s\S]* can span lines, but s usually expresses the intent more directly in modern JavaScript.

Debugging a specific Regex issue? Browse Regex troubleshooting.