System.Text.RegularExpressions.Regex.Unescape Method

Converts any escaped characters in the input string.

Syntax

public static string Unescape (string str)

Parameters

str
The input string containing the text to convert.

Returns

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

Remarks

The Regex.Unescape(string) method performs one of the following two transformations:

  • It reverses the transformation performed by the Regex.Escape(string) method by removing the escape character ("\") from each character escaped by the method. These include the \, *, +, ?, |, {, [, (,), ^, $,., #, and white space characters. In addition, the Regex.Unescape(string) method unescapes the closing bracket (]) and closing brace (}) characters.

Note:

Regex.Unescape(string) cannot reverse an escaped string perfectly because it cannot deduce precisely which characters were escaped,

  • It replaces the representation of unprintable characters with the characters themselves. For example, it replaces \a with \x07. The character representations it replaces are \a, \b, \e, \n, \r, \f, \t, and \v.

If the Regex.Unescape(string) method encounters other escape sequences that it cannot convert, such as \w or \s, it throws an ArgumentException.

Requirements

Namespace: System.Text.RegularExpressions
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0