February 2019
Intermediate to advanced
626 pages
15h 51m
English
By default, every group is a capture group. A group can be marked as non-capturing by using ?: before the expression. In the following example, the third group has been marked as a non-capturing group:
PS> 'first second third' -match '(?<One>first) (?<Two>second) (?:third)'TruePS> $matchesName Value---- -----Two secondOne first0 first second third
The outer group, which previously added second third to the matches list, is now excluded from the results:
PS> 'first second third' -match '(first) (?:(second) (third))'; $matchesTruePS> $matchesName Value---- -----3 third2 second1 first0 first second third
This technique may be useful when using -replace—it simplifies the list of tokens available, even if an expression grows ...
Read now
Unlock full access