While many people think that ^
means the start of a string, it actually means start of a line. For an actual start of string anchor use, \A
.
The string hello\nworld
(or more clearly)
hello
world
Would be matched by the regular expressions ^h
, ^w
and \Ah
but not by \Aw