This article describes the string substitution operator in PowerShell: Replace. In Replace, you can use regular expressions, which greatly improves the functionality of replace.
Copy Code code as follows:
Ps> ' unit1,unit2,unit3 '-replace ' [, T] ', '; '
Unit1; Unit2; Unit3
The above example uses a comma (,) or tab (\ t) from the given string to replace the component number (;). This is a very common application that is often needed to construct a CSV file. A CSV file is a semicolon-delimited data for each cell.
The use of the replace operator is:
Copy Code code as follows:
< pending strings >-replace < find character >,< replacement character >
Explain the meaning of this grammar, which is to find the < lookup character in the < pending string >, and replace the < lookup character > with the < replacement character >. Here,< find characters > You can use regular expressions. Finding a match through a regular expression will greatly enhance the function of the replace operator.
About the use of Replace operator and regular expression in PowerShell, this article introduces so many, hope to help you, thank you!