Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
Regex.Escape(String) Method
Definition
- Namespace:
- System.Text.RegularExpressions
- Assemblies:
- System.dll, System.Text.RegularExpressions.dll
- Assemblies:
- netstandard.dll, System.Text.RegularExpressions.dll
- Assembly:
- System.Text.RegularExpressions.dll
- Assembly:
- System.dll
- Assembly:
- netstandard.dll
- Source:
- Regex.cs
- Source:
- Regex.cs
- Source:
- Regex.cs
- Source:
- Regex.cs
- Source:
- Regex.cs
Important
Some information relates to prerelease product that may be substantially modified before itβs released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Escapes a minimal set of characters (, *, +, ?, |, {, [, (, ), ^, $, ., #, and white space) by replacing them with their escape codes. This instructs the regular expression engine to interpret these characters literally rather than as metacharacters.
public:
static System::String ^ Escape(System::String ^ str);
public static string Escape(string str);
static member Escape : string -> string
Public Shared Function Escape (str As String) As String
Parameters
- str
- String
The input string that contains the text to convert.
Returns
A string of characters with metacharacters converted to their escaped form.
Exceptions
str is null.
Remarks
Escape(String) converts a string so that the regular expression engine will interpret any metacharacters that it may contain as character literals. It is particularly important for strings that are defined dynamically using characters not known at design time.
While this method escapes the straight opening bracket ([) and opening brace ({) characters, it does not escape their corresponding closing characters (] and }). In most cases, escaping these is not necessary.
Applies to
See also
Feedback
Was this page helpful?
