Regex options
Regular expression options are used to control the behavior of certain characters in an expression.
Some aspects of the behavior of a regular expression can be modified by placing a regex option either at the beginning or around part of an expression.
In the following example, .+
will only match the first line; the result of the whole match is in the 0
key in the $matches
Hashtable:
PS> "First line`nSecond line" -match '.+'
True
PS> $matches[0]
First line
This is because dot (.
) will not match line break characters by default. You can change this by setting a single-line option for the expression:
PS> "First line`nSecond line" -match '(?s).+'
True
PS> $matches[0]
First line
Second line
Table 9.7 shows various regex options and their effect:
Character |
Description | ...