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

Doctor Scripto

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

0 comments

Discussion is closed.

Feedback usabilla icon