What it does
^ and $ assert positions, not characters. With flag m they apply at every line start and end instead of only the whole text.
How to use it
- Load the example: ^cat$ with flag m on two lines.
- Remove flag m and run again to see the difference.
- Check the counterexample: cat inside bobcat.
Verified example
Example
Text "cat\ncat"
^cat$ Result: "cat", "cat"
^cat$ Result: "cat", "cat"
^cat$ Result: "cat", "cat"
^cat$ Result: "cat", "cat"
Counterexample
Text "bobcat"
^cat$ Result: no match
^cat$ Result: no match
^cat$ Result: no match
^cat$ Result: no match
Recorded by running fixture FX-S01 on : rp.js@1 on Node v24.21.0 (V8), v24.21.0, CPython 3.14.2 (Pyodide 314.0.7), PCRE2 10.48, go1.27.1. JavaScript results come from the rp.js@1 core on Node’s V8; your browser runs the same core.
Engines
- In Python and PCRE2, $ without m also matches before a final line feed.
Limits
- Matching the whole text with m is not the same as running each line separately.