Powershell replace regex

In this article let’s discuss about Powershell replace regex. Let’s go through the following methods without any delay.

Method 1:

# 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!

Hope the above solution works.

Realted Posts : Grep literal string