November 7th, 2015

PowerTip: Replace Non-Alphabetic Characters in String

Doctor Scripto
Scripter

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

Hey, Scripting Guy! Question How can I use Windows PowerShell to replace a string that contains non-alphabetic characters
           (such as commas and periods)?

Hey, Scripting Guy! Answer Use the –Replace operator, and specify a regex pattern ‘[^a-zA-Z]’, for example:

$a = ‘Never a foot too far, even.’

$a -Replace ‘[^a-zA-Z]’,”

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.