{"id":77895,"date":"2016-04-15T14:51:34","date_gmt":"2016-04-15T14:51:34","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=77895"},"modified":"2019-02-18T09:10:48","modified_gmt":"2019-02-18T16:10:48","slug":"powertip-use-a-regular-expression-pattern-to-remove-nonalphabetic-characters","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-use-a-regular-expression-pattern-to-remove-nonalphabetic-characters\/","title":{"rendered":"PowerTip: Use a regular expression pattern to remove nonalphabetic characters"},"content":{"rendered":"<p><strong>Summary<\/strong>: Learn how to use a regular expression pattern to remove non-alphabetic characters from a string by using Windows PowerShell.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>\u00a0How can I use Windows PowerShell to remove non-alphabetic characters from a string?<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>\u00a0To remove nonalphabetic characters from a string, you can use the <strong>-Replace<\/strong> operator and substitute an empty string <strong>\u2018\u2019<\/strong> 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 (<strong>^<\/strong>) in the series symbol. Here is an example:<\/p>\n<p style=\"padding-left: 90px\">$string = &#8216;abcdefg12345HIJKLMNOP!@#$%qrs)(*&amp;^TUVWXyz&#8217;<\/p>\n<p style=\"padding-left: 90px\">$pattern = &#8216;[^a-zA-Z]&#8217;<\/p>\n<p style=\"padding-left: 90px\">$string -replace $pattern, &#8216; &#8216;<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7610.Dr.ScriptoForTips.jpg\" alt=\"The Doctor\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use a regular expression pattern to remove non-alphabetic characters from a string by using Windows PowerShell. \u00a0How can I use Windows PowerShell to remove non-alphabetic characters from a string? \u00a0To remove nonalphabetic characters from a string, you can use the -Replace operator and substitute an empty string \u2018\u2019 for the nonalphabetic [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,639,686,687,688,641],"tags":[356,526,174,3,689,45],"class_list":["post-77895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-powertip","category-regex","category-regular-expressions","category-text-manipulation","category-windows-powershell","tag-powertip","tag-regex","tag-regular-expressions","tag-scripting-guy","tag-text-manipulation","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use a regular expression pattern to remove non-alphabetic characters from a string by using Windows PowerShell. \u00a0How can I use Windows PowerShell to remove non-alphabetic characters from a string? \u00a0To remove nonalphabetic characters from a string, you can use the -Replace operator and substitute an empty string \u2018\u2019 for the nonalphabetic [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=77895"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77895\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=77895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=77895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=77895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}