{"id":80235,"date":"2016-09-30T11:59:57","date_gmt":"2016-09-30T18:59:57","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=80235"},"modified":"2019-02-18T09:10:26","modified_gmt":"2019-02-18T16:10:26","slug":"powertip-how-to-escape-characters-in-a-string-using-regular-expressions","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-how-to-escape-characters-in-a-string-using-regular-expressions\/","title":{"rendered":"PowerTip: How to escape characters in a string using regular expressions"},"content":{"rendered":"<p><strong>Summary<\/strong>: Cloud &amp; Datacenter Management MVP, Thomas Rayner, shows how escape characters for use in regex.<\/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\" \/> Is there a way to escape characters in a string automatically for use in regex?<\/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\" \/>\u00a0Use the <code>[regex]::escape()<\/code> method to automatically escape characters in a string so you can use them in regex.<\/p>\n<p style=\"padding-left: 90px\"><em><code>[regex]::escape('something. in here (needs) escaping')<\/code><\/em><\/p>\n<p style=\"padding-left: 90px\"><em><code>something\\.\\ in\\ here\\ \\(needs\\)\\ escaping<\/code><\/em><\/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: Cloud &amp; Datacenter Management MVP, Thomas Rayner, shows how escape characters for use in regex. Is there a way to escape characters in a string automatically for use in regex? \u00a0Use the [regex]::escape() method to automatically escape characters in a string so you can use them in regex. [regex]::escape(&#8216;something. in here (needs) escaping&#8217;) something\\.\\ [&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,641],"tags":[56,356,652,45],"class_list":["post-80235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-powertip","category-regex","category-windows-powershell","tag-guest-blogger","tag-powertip","tag-thomas-rayner","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Cloud &amp; Datacenter Management MVP, Thomas Rayner, shows how escape characters for use in regex. Is there a way to escape characters in a string automatically for use in regex? \u00a0Use the [regex]::escape() method to automatically escape characters in a string so you can use them in regex. [regex]::escape(&#8216;something. in here (needs) escaping&#8217;) something\\.\\ [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80235","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=80235"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80235\/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=80235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=80235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=80235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}