In JavaScript, regex.multiline is a read-only boolean. It is true when the RegExp was created with the m flag.
With m, the anchors ^ and $ match the start and end of each line, not only the whole string. Without m, they match only the start and end of the entire text.
Syntax
Create the regex with m, then read .multiline.
JavaScript
const a = /end$/;
const b = /end$/m;
const c = new RegExp("end$", "m");
console.log(a.multiline); // false
console.log(b.multiline); // true
console.log(c.multiline); // true
Call
What it does
/end$/
Anchors apply to the whole string. multiline is false.
/end$/m
Anchors apply per line. multiline is true.
new RegExp("end$", "m")
Same as the literal with m.
Remember this at a glance:
Remember
/hello$/.multiline → false
/hello$/m.multiline → true
without m: ^ and $ → whole string only
with m: ^ and $ → start/end of every line
flags are fixed at creation — cannot set .multiline = true
What You Get
Name
Description
regex.multiline
Read-only. true if the m flag was set when the RegExp was created.
m flag
Set at creation with /…/m or new RegExp(pattern, "m").
^ and $
With m, match the start and end of each line (split by newline).
Return Value
Value
Description
true
The RegExp has the m (multiline) flag.
false
The RegExp does not have the m flag.
JavaScript Examples
Example 1 — Read multiline
See how the m flag sets the property.
JavaScript
const a = /end$/;
const b = /end$/m;
const c = new RegExp("^start", "m");
console.log(a.multiline);
console.log(b.multiline);
console.log(c.multiline);
console.log(c.flags);