I have google around this but have been unsuccessful in finding an answer. The following code gives unexpected results. I would expect the string “some string with a question mark in it” to be returned. But instead the original string is returned. The question mark seems to be causing issues. It doesn’t seem to be acting like a regex wild card or any other sort of wild card. Is this expected behavior and if so how do you escape a question mark so I can search for a string containing a question mark
"some string w?th a question mark in it" -replace 'w?th', 'with'
PowerShell’s -replace operator uses regular expressions. In this case, you’d just need to escape that question mark with a backslash, because the question mark is a special character in regex:
"some string w?th a question mark in it" -replace 'w\?th', 'with'