Useless Flag ‘m’ (Multiline)

Identifier: regex.lint.flag.useless.m

When it triggers: The pattern sets the m (multiline) modifier but contains no start/end anchors (^ or $). \A, \z and \Z are not read by m, so they do not count.

Message: Flag 'm' is useless: the pattern contains no ^ or $ anchor.

Visual Explanation:

/search_term/m
  -> no ^ or $ anchors
  -> m has no effect

Example:

// Warning: Multiline mode is unused because there are no anchors
preg_match('/search_term/m', $text);

// Preferred: Remove unnecessary flag
preg_match('/search_term/', $text);

Fix: Remove the flag or add anchors for per-line matching.

Read more:


Try it. Open /search_term/m in the playground: the finding is in the Diagnostics tab.

Edit on GitHub Feedback