Regex Multiline Anchors – Use the JavaScript m Flag

Local only

Fix a valid anchored regex that misses a complete line because multiline mode is not enabled.

15 chars · 3 lines

8 chars · 1 line

Pattern did not match the inputFlags: g

Regex multiline behavior

How to make ^ and $ match individual lines

Without m, ^ERROR$ applies to the boundaries of the complete input, so it does not find ERROR in the middle line of a multiline string. Add the JavaScript m flag when anchors should also recognize line boundaries. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Valid regex behavior check
  • Multiline anchor comparison
  • JavaScript m flag
  • Match or No match output
  • Flag debugging
  • Browser-local processing

Steps

  1. Confirm that the target line is correct but is not at the start or end of the complete input.
  2. Add m once to the Flags field.
  3. Retest the multiline sample and verify that the anchors still express the intended line-level rule.

m changes anchors, not the dot wildcard

Multiline mode changes how ^ and $ behave. It does not make . match newlines; that behavior belongs to the s flag.

Multiline anchor example

Keep ^ERROR$ and enable multiline mode.

Pattern and flags

^ERROR$ / no flags

Corrected flags

m

Common questions

Frequently asked questions

Why does ^ERROR$ miss a middle line?

Without m, the anchors refer to the complete input boundaries rather than every line boundary.

Does m make dot match newlines?

No. Use s for dotAll behavior.

Can I combine m and i?

Yes, if you need both multiline anchors and case-insensitive matching.

Debugging a specific Regex issue? Browse Regex troubleshooting.