February 2019
Intermediate to advanced
626 pages
15h 51m
English
The -replace operator performs replacement based on a regular expression. For example, it can be used to replace several instances of the same thing:
PS> 'abababab' -replace 'a', 'c'cbcbcbcb
In the example, a is the regular expression that dictates what must be replaced. 'c' is the value any matching values should be replaced with.
This syntax can be generalised, as follows:
<Value> -replace <Match>, <Replace-With>
If the Replace-With value is omitted, the matches will be replaced with nothing (that is, they are removed):
PS> 'abababab' -replace 'a'bbbb
Regular expressions use parentheses to capture groups. The replace operator can use those groups. Each group may be used in the Replace-With argument. For example, a set of values ...
Read now
Unlock full access