Regex
Definition
Namespace: Corvus.Ecma262.RegularExpressions
Assembly: Corvus.Regex.Ecma262.dll
Source: Regex.cs
An ECMA-262 regular expression: the grammar and the answers of ECMAScript 2025, with the shape of System.Text.RegularExpressions.Regex. It matches UTF-16 text (String and ReadOnlySpan of Char ) and UTF-8 text (ReadOnlySpan of Byte ) natively, with no transcoding either way. An instance is immutable and safe to share between threads.
public sealed class Regex
Inheritance
Object → Regex
Constructors
Constructor
Description
Regex(...)
Initializes a new instance of the Regex class with no flags.
Properties
Methods
Method
Description
Count
The number of matches in a text.
EnumerateMatches
Enumerates the matches in a UTF-16 text, allocating nothing.
EnumerateSplits
Enumerates the pieces a UTF-16 text splits into at the matches, as positions, allocating nothing. The pieces are those of Split without...
Escape(string) static
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...
GetGroupNames()
The names of the named groups, in the order the pattern first uses them.
GroupNameFromNumber(int)
The name of a group, or its number as text when it has none.
GroupNumberFromName(string)
The number of the first group of a name, or -1 when the pattern has no group of that name.
IsMatch static
Whether a pattern matches anywhere in a text, with no flags.
IsValid(string, RegexFlags) static
Whether a pattern is a valid ECMA-262 pattern in the grammar of the flags.
Match static
The first match of a pattern in a text, with no flags.
Matches static
Every match of a pattern in a text.
ParseFlags(string) static
Reads the flags as the string new RegExp(pattern, flags) takes.
Replace static
Replaces the matches of a pattern in a text (every match with Global , the first otherwise).
Split static
Splits a text at the matches of a pattern, as String.prototype.split does.
ToString()
TryCreate(string, RegexFlags, Regex?, string?) static
Creates a regular expression without throwing for a pattern that is not valid.
TryMatch
Finds the first match in a UTF-16 text at or after a position and reports what each group captured, allocating nothing.
TryReplace
Replaces the matches in a UTF-16 text (every match with Global , the first otherwise) and writes the result to a span, allocating n...
Unescape(string) static
Reverses Escape : reads the escapes it writes, and a backslash before any other character as that character.
Fields
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