powershell replace regex 1

powershell replace regex

# You can supply regular expressions to the 
# first parameter of the replace operator.

$str = "Hello world!"
$str -replace "world|earth|mars", "unspecified planetary body"

# Output: Hello unspecified planetary body!

Here is what the above code is Doing:
1. The first line creates a string variable called $str and assigns it the value “Hello world!”
2. The second line uses the -replace operator to replace the words “world”, “earth”, and “mars” with the phrase “unspecified planetary body”.
3. The third line is a comment that shows the output of the second line.

Similar Posts