PowerTip: Use a regular expression pattern to remove nonalphabetic characters
Summary: Learn how to use a regular expression pattern to remove non-alphabetic characters from a string by using Windows PowerShell.
To remove nonalphabetic characters from a string, you can use the -Replace operator and substitute an empty string ‘’ for the nonalphabetic character. The secret to doing this is to create a pattern on characters that you want to include and then using the not (^) in the series symbol. Here is an example:
$string = ‘abcdefg12345HIJKLMNOP!@#$%qrs)(*&^TUVWXyz’
$pattern = ‘[^a-zA-Z]’
$string -replace $pattern, ‘ ‘