Skip to content

Regex.TryCreate Method

Definition

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

Overloads

Method Description
TryCreate(string, RegexFlags, Regex?, string?) Creates a regular expression without throwing for a pattern that is not valid.
TryCreate(string, RegexFlags, TimeSpan, Regex?, string?) Creates a regular expression with a match timeout without throwing for a pattern that is not valid.
TryCreate(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion, Regex?, string?) Creates a regular expression with a match timeout, the edition of the grammar and the version of Unicode, without throwing for a pattern that is not valid.
TryCreate(string, RegexFlags, TimeSpan, RegexEdition, RegexUnicodeVersion, RegexBuildOptions, Regex?, string?) Creates a regular expression with a match timeout, the edition of the grammar, the version of Unicode and when what its matches use is built, without throwing for a pattern that is not valid.

TryCreate(string, RegexFlags, Regex?, string?)

Source: Regex.cs

Creates a regular expression without throwing for a pattern that is not valid.

public static bool TryCreate(string pattern, RegexFlags flags, out Regex? regex, out string? error)

Parameters

Name Type Description
pattern string The pattern.
flags RegexFlags The flags.
regex Regex? The regular expression, or null.
error string? Why the pattern was refused, or null.

Returns

bool

true when the pattern is valid in the grammar of its flags and not over a limit of size.

Applies To

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

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

Source: Regex.cs

Creates a regular expression with a match timeout without throwing for a pattern that is not valid.

public static bool TryCreate(string pattern, RegexFlags flags, TimeSpan matchTimeout, out Regex? regex, out string? error)

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.
regex Regex? The regular expression, or null.
error string? Why the pattern was refused, or null.

Returns

bool

true when the pattern is valid in the grammar of its flags and not over a limit of size.

Applies To

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

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

Source: Regex.cs

Creates a regular expression with a match timeout, the edition of the grammar and the version of Unicode, without throwing for a pattern that is not valid.

public static bool TryCreate(string pattern, RegexFlags flags, TimeSpan matchTimeout, RegexEdition edition, RegexUnicodeVersion unicodeVersion, out Regex? regex, out string? error)

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.
regex Regex? The regular expression, or null.
error string? Why the pattern was refused, or null.

Returns

bool

true when the pattern is valid in the grammar of its flags and edition and not over a limit of size.

Applies To

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

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

Source: Regex.cs

Creates a regular expression with a match timeout, the edition of the grammar, the version of Unicode and when what its matches use is built, without throwing for a pattern that is not valid.

public static bool TryCreate(string pattern, RegexFlags flags, TimeSpan matchTimeout, RegexEdition edition, RegexUnicodeVersion unicodeVersion, RegexBuildOptions buildOptions, out Regex? regex, out string? error)

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 (see RegexBuildOptions).
regex Regex? The regular expression, or null.
error string? Why the pattern was refused, or null.

Returns

bool

true when the pattern is valid in the grammar of its flags and edition and not over a limit of size.

Exceptions

Exception Description
ArgumentOutOfRangeException The build options are not RegexBuildOptions.

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