C#

January 24, 2014

C# String extension method to escape characters for regular expressions (regex)

By |2014-01-24T07:43:31+00:00January 24th, 2014|Categories: C#, Handy Tools/Utilities|

I needed a way to escape special regex characters in a string. These characters include the following: ".", "$", "^", "{", "[", "(", "|", ")", "*", "+", "?", "\\" . This list was obtained from http://msdn.microsoft.com/en-us/library/4edbef7e(v=vs.110).aspx Here is a small string extension method that will accomplish this: Edit*- 1/24/13 - I didn't realize there was a built in [...]