DELAPARRA
Index
Color
NL
Category: Regex flags

/m (Multiline)

Explained by Updated

What is /m (Multiline)?

/m (Multiline): Makes ^ and $ match the start and end of each line, not just the whole string. The m flag, short for multiline, changes what ^ and $ mean. Normally they match the start and end of the whole string. With m, they match the start and end of every line.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about /m (Multiline)

How is /m (Multiline) used in practice?

So /^error/m finds lines that begin with error anywhere in a log file. Without the flag it would only check the first line. This is the flag you want when you process text that contains many lines, such as logs, config files or CSV exports.

What should you keep in mind with /m (Multiline)?

People often confuse it with the s flag, which makes . match newline characters. They solve different problems and can be combined. If a pattern works on a single line in your test but finds nothing in a real file, a missing m is a likely cause. If you need the true start or end of the whole string while m is on, use \A and \z.

At a glance

CategoryRegex flags
Explained by
Updated

More Regex flags terms

All terms starting with a number or symbol

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.