^Match the starting position of a row or string;
In enhancement mode, ^ matches the position after each line break.
NOTE: If there are multiple lines of text, for example:
First linesecond line
The actual content is:
First line [Cr] [LF] Second line
[Cr] carriage return
[LF] line feed
Therefore, in the enhancement mode,^It can match the starting position of each line of text. The reason for this explanation is that it conforms to our eye habits.
Note:$This can cause us a headache.
$Matches the end position of a string/line, but in enhancement mode,$It can match the linefeed inside the string.
Instance:
Text/string:ABC
Regular Expression:^ ABC $
Matching result:ABC
String:
123456
Regular Expression:(? M) ^ \ D {3} $
Matching result:456
Note:(? M)Enable the enhancement mode.
Why does the first row 123 fail to match?
Because$The carriage return cannot match.
123 [Cr] [LF] 456
Think about why 123 cannot be matched, and why 456 can be matched.