September 30th, 2016

PowerTip: How to escape characters in a string using regular expressions

Doctor Scripto
Scripter

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how escape characters for use in regex.

Hey, Scripting Guy! Question Is there a way to escape characters in a string automatically for use in regex?

Hey, Scripting Guy! Answer Use the [regex]::escape() method to automatically escape characters in a string so you can use them in regex.

[regex]::escape('something. in here (needs) escaping')

something\.\ in\ here\ \(needs\)\ escaping

The Doctor

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.