February 2019
Intermediate to advanced
626 pages
15h 51m
English
Alternation is the lowest precedence operator. In a sense, it might be wise to consider it as describing an ordered list of regular expressions to test.
Placing an alternation statement in parentheses reduces the scope of the expression.
For example, it is possible to match a multi-line string using alternation as follows:
PS> $string = @'First linesecond linethird line'@PS> if ($string -match 'First(.|\r?\n)*line') { $matches[0] }First linesecond linethird line
In this example, as . does not match the end of line character, using alternation allows each character to be tested against a broader set. In this case, each character is tested to see whether it is any character, \r\n or \n.
A regular expression might be ...
Read now
Unlock full access