Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Use PowerShell to Replace Characters in String

$
0
0

Summary: Use Windows PowerShell to replace non-alphabetic and non-number characters in a string.

Hey, Scripting Guy! Question How can I use Windows PowerShell to replace every non-alphabetic and non-number character in a string
           with a hyphen?

Hey, Scripting Guy! Answer Use the Windows PowerShell –Replace operator and the \w regular expression character class.
           The \w character class includes the letters a-z, A-Z, and numbers. Here is an example:

PS C:\> $s = 'abc.123,DEF&ghi'

PS C:\> $s -replace "\w", '-'

---.---,---&---

PS C:\>  


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>