Multiline Mode
By default, ^ and $ match the start and end of the entire string. The multiline flag (m) changes this behavior.
Default Behavior
Only the first "Hello" matches because ^ means start of the entire string.
With Multiline Flag
Now both lines starting with "Hello" match! The m flag makes ^ match at line starts.
Exercises
Full Line Matching
Practical Examples
Log File Example
The s Flag (Dotall)
The s flag makes . match newlines too:
Without s, . doesn't match the newline characters, so the pattern fails.
Practice Playground
Try with m flag:
^#- comment lines start^[a-z]+=- config lines^$- empty lines^\s*$- blank lines
Key Takeaways
- Default:
^and$match string start/end - Multiline (
m):^and$match line start/end - Use
^...$withmflag to match entire lines - The
sflag makes.match newlines - Combine flags as needed:
gm,gi,gms

