Skip to content

Regex Constructors

Definition

Namespace: Corvus.Ecma262.RegularExpressions
Assembly: Corvus.Regex.Ecma262.dll

Overloads

Constructor Description
Regex(string) Initializes a new instance of the Regex class with no flags and the...
Regex(string, RegexFlags) Initializes a new instance of the Regex class with the...
Regex(string, string) Initializes a new instance of the Regex class, with the flags as new RegExp(pattern, flags) takes them and the...
Regex(string, RegexFlags, TimeSpan) Initializes a new instance of the Regex class with a match timeout: the time each match may take before it is abandoned with...
Regex(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion) Initializes a new instance of the Regex class with a match timeout, the edition of the grammar and the version of Unicode, which are independe...
Regex(string, RegexFlags, TimeSpan, GeneratedRunner?, GeneratedRunner?) Initializes a new instance of the Regex class whose programs run as the generated code given rather than the interpreter: the seam for the sou...
Regex(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion, GeneratedRunner?, GeneratedRunner?) Initializes a new instance of the Regex class whose programs run as the generated code given rather than the interpreter: the seam for the sou...
Regex(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion, RegexBuildOptions) Initializes a new instance of the Regex class with a match timeout, the edition of the grammar, the version of Unicode, and when what its matc...
Regex(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion, GeneratedRunner?, GeneratedRunner?, ReadOnlySpan<byte>) Initializes a new instance of the Regex class from the compiled form the source generator wrote, with its programs run as the generated code g...

Regex(string)

Source: Regex.cs

Initializes a new instance of the Regex class with no flags and the DefaultMatchTimeout.

public Regex(string pattern)

Parameters

Name Type Description
pattern string The pattern.

Exceptions

Exception Description
RegexParseException The pattern is not valid.
RegexPatternTooLargeException The pattern is over a limit of size.

Applies To

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

Regex(string, RegexFlags)

Source: Regex.cs

Initializes a new instance of the Regex class with the DefaultMatchTimeout.

public Regex(string pattern, RegexFlags flags)

Parameters

Name Type Description
pattern string The pattern.
flags RegexFlags The flags.

Exceptions

Exception Description
RegexParseException The pattern is not valid in the grammar of its flags.
RegexPatternTooLargeException The pattern is over a limit of size.

Applies To

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

Regex(string, string)

Source: Regex.cs

Initializes a new instance of the Regex class, with the flags as new RegExp(pattern, flags) takes them and the DefaultMatchTimeout.

public Regex(string pattern, string flags)

Parameters

Name Type Description
pattern string The pattern.
flags string The flags: any of d, g, i, m, s, u, v and y, each at most once.

Exceptions

Exception Description
RegexParseException The pattern is not valid in the grammar of its flags, or the flags are not valid.
RegexPatternTooLargeException The pattern is over a limit of size.

Applies To

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

Regex(string, RegexFlags, TimeSpan)

Source: Regex.cs

Initializes a new instance of the Regex class with a match timeout: the time each match may take before it is abandoned with RegexMatchTimeoutException. A match with a timeout is also abandoned, with ExceededMemory, when its backtracking stack reaches its cap. Every member that matches gives each of its matches the timeout, whatever the pattern. Without one a match has no limit of time or of memory, so a pattern or a text from outside should be given one, here or for every instance with DefaultMatchTimeout.

public Regex(string pattern, RegexFlags flags, TimeSpan matchTimeout)

Parameters

Name Type Description
pattern string The pattern.
flags RegexFlags The flags.
matchTimeout TimeSpan The time a match may take before it is abandoned with RegexMatchTimeoutException, or InfiniteMatchTimeout.

Exceptions

Exception Description
RegexParseException The pattern is not valid in the grammar of its flags.
RegexPatternTooLargeException The pattern is over a limit of size.

Applies To

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

Regex(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion)

Source: Regex.cs

Initializes a new instance of the Regex class with a match timeout, the edition of the grammar and the version of Unicode, which are independent of each other. A validator of JSON Schema 2020-12, which names ECMAScript 2020, takes Es2020.

public Regex(string pattern, RegexFlags flags, TimeSpan matchTimeout, RegexEdition edition, RegexUnicodeVersion unicodeVersion)

Parameters

Name Type Description
pattern string The pattern.
flags RegexFlags The flags.
matchTimeout TimeSpan The time a match may take before it is abandoned with RegexMatchTimeoutException, or InfiniteMatchTimeout.
edition RegexEdition The edition of ECMA-262 whose grammar the pattern is read with.
unicodeVersion RegexUnicodeVersion The version of Unicode whose character database the pattern is read with.

Exceptions

Exception Description
RegexParseException The pattern is not valid in the grammar of its flags and edition.
RegexPatternTooLargeException The pattern is over a limit of size.

Applies To

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

Regex(string, RegexFlags, TimeSpan, GeneratedRunner?, GeneratedRunner?)

Source: Regex.cs

Initializes a new instance of the Regex class whose programs run as the generated code given rather than the interpreter: the seam for the source generator, not for use by hand.

public Regex(string pattern, RegexFlags flags, TimeSpan matchTimeout, GeneratedRunner? bounds, GeneratedRunner? captures)

Parameters

Name Type Description
pattern string The pattern.
flags RegexFlags The flags.
matchTimeout TimeSpan The limit of time on a match.
bounds GeneratedRunner? The generated code for the program that finds a match's bounds, or null.
captures GeneratedRunner? The generated code for the program that tracks every group, or null.

Applies To

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

Regex(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion, GeneratedRunner?, GeneratedRunner?)

Source: Regex.cs

Initializes a new instance of the Regex class whose programs run as the generated code given rather than the interpreter: the seam for the source generator, not for use by hand.

public Regex(string pattern, RegexFlags flags, TimeSpan matchTimeout, RegexEdition edition, RegexUnicodeVersion unicodeVersion, GeneratedRunner? bounds, GeneratedRunner? captures)

Parameters

Name Type Description
pattern string The pattern.
flags RegexFlags The flags.
matchTimeout TimeSpan The limit of time on a match.
edition RegexEdition The edition of the grammar.
unicodeVersion RegexUnicodeVersion The version of Unicode.
bounds GeneratedRunner? The generated code for the program that finds a match's bounds, or null.
captures GeneratedRunner? The generated code for the program that tracks every group, or null.

Applies To

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

Regex(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion, RegexBuildOptions)

Source: Regex.cs

Initializes a new instance of the Regex class with a match timeout, the edition of the grammar, the version of Unicode, and when what its matches use is built: with Eager, in the constructor, so that the first match costs what a later one does.

public Regex(string pattern, RegexFlags flags, TimeSpan matchTimeout, RegexEdition edition, RegexUnicodeVersion unicodeVersion, RegexBuildOptions buildOptions)

Parameters

Name Type Description
pattern string The pattern.
flags RegexFlags The flags.
matchTimeout TimeSpan The time a match may take before it is abandoned with RegexMatchTimeoutException, or InfiniteMatchTimeout.
edition RegexEdition The edition of ECMA-262 whose grammar the pattern is read with.
unicodeVersion RegexUnicodeVersion The version of Unicode whose character database the pattern is read with.
buildOptions RegexBuildOptions When what the matches use is built.

Exceptions

Exception Description
RegexParseException The pattern is not valid in the grammar of its flags and edition.
RegexPatternTooLargeException The pattern is over a limit of size.
ArgumentOutOfRangeException The build options are not RegexBuildOptions.

Applies To

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

Regex(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion, GeneratedRunner?, GeneratedRunner?, ReadOnlySpan<byte>)

Source: Regex.cs

Initializes a new instance of the Regex class from the compiled form the source generator wrote, with its programs run as the generated code given: the seam for the source generator, not for use by hand. Nothing is parsed or built when the image was written by this version of the engine for these settings; otherwise the image is ignored and the pattern is parsed, with the same answers.

public Regex(string pattern, RegexFlags flags, TimeSpan matchTimeout, RegexEdition edition, RegexUnicodeVersion unicodeVersion, GeneratedRunner? bounds, GeneratedRunner? captures, ReadOnlySpan<byte> compiled)

Parameters

Name Type Description
pattern string The pattern.
flags RegexFlags The flags.
matchTimeout TimeSpan The limit of time on a match.
edition RegexEdition The edition of the grammar.
unicodeVersion RegexUnicodeVersion The version of Unicode.
bounds GeneratedRunner? The generated code for the program that finds a match's bounds, or null.
captures GeneratedRunner? The generated code for the program that tracks every group, or null.
compiled ReadOnlySpan<byte> The image of the compiled regular expression, or empty.

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