Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Regex.Escape Method

Escapes a minimal set of metacharacters (\, *, +, ?, |, {, [, (,), ^, $, ., #, and white space) by replacing them with their escape codes.

[Visual Basic]
Public Shared Function Escape( _
   ByVal str As String _
) As String
[C#]
public static string Escape(
 string str
);
[C++]
public: static String* Escape(
 String* str
);
[JScript]
public static function Escape(
   str : String
) : String;

Parameters

str
The input string containing the text to convert.

Return Value

A string of characters with any metacharacters converted to their escaped form.

Remarks

Escape converts a string so it can be used as a constant within a regular expression. (The number sign (#) and white-space characters must be escaped so the string can be used within an expression parsed with the IgnorePatternWhitespace option enabled. If future .NET regular expression features add additional metacharacters, Escape converts those characters to escaped form as well.)

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Regex Class | Regex Members | System.Text.RegularExpressions Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft