Skip to content

Regex.Escape Method

Definition

Namespace: Corvus.Ecma262.RegularExpressions
Assembly: Corvus.Regex.Ecma262.dll
Source: Regex.Matching.cs

Escape(string)

Escapes a text so that it matches itself as a pattern, as RegExp.escape of ECMAScript 2025 does: a first character that is a letter or a digit, the syntax characters, the other punctuators, white space, line terminators and lone surrogates are written as escapes.

public static string Escape(string text)

Parameters

Name Type Description
text string The text.

Returns

string

The pattern.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests.

Open an issue