Search notes:

Regular expressions: Multi line mode

When multi line mode is enabled in a regular expression, the two special characters ^ and $ not only match at the beginning or end of the input text, but also right before or after a new line.
Within a regular expression, multi line mode can be enabled with (?m)… (Perl regexp flavor).
The following PowerShell example tries to demonstrate the difference between default and multi-line mode:
By default, $ does only match at the end of the input string;
PS C:\> "one`ntwo`nthree" -replace '$', ' EOL'
one
two
three EOL
However, with mutli line mode, all «end of lines» are replaced;
PS C:\> "one`ntwo`nthree" -replace '(?m)$', ' EOL'
one EOL
two EOL
three EOL

See also

With single line mode (which is not mutually exclusive to multi line mode), a dot . matches any character, including a new line.
Regular expressions.

Index