Why is \D+ matching across new lines, despite using multiline flag?
02:52 12 Jun 2026

let str = `a
b`;

// ✔
for (let match of str.matchAll (/^.+$/mg))
  console.log (match);

// ✔ 
for (let match of str.matchAll (/^[^0-9]$/mg))
  console.log (match);

// ⚠️ problem
for (let match of str.matchAll (/^\D+$/mg))
  console.log (match);

/**
Output:
["a"]
["b"]

["a"]
["b"]

// ⚠️ problem
["a\nb"]
*/

javascript regex