October 2017
Intermediate to advanced
440 pages
11h 47m
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:
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 if it is any character, \r\n or \n.
A regular expression might be created to look ...
Read now
Unlock full access