Question:
This works:
1 2 3 |
$string = "This string, has a, lot, of commas in, it." $string -replace ',','' |
Output: This string has a lot of commas in it.
But this doesn’t work:
1 2 3 |
$string = "This string. has a. lot. of dots in. it." $string -replace '.','' |
Output: blank.
Why?
Answer:
-replace
searches using regular expressions (regexp), and in regexps the dot is a special character. Escape it using ‘\
‘, and it should work. See Get-Help about_Regular_Expressions
.