Class Regex
Represents a pattern that must be matched by terminals in a grammar.
public sealed class Regex
- Inheritance
-
Regex
Properties
Any
A Regex that matches any character.
public static Regex Any { get; }
Property Value
Empty
A Regex that matches the empty string.
public static Regex Empty { get; }
Property Value
Methods
AtLeast(int)
Creates a Regex that matches this regex at least a specific number of times.
public Regex AtLeast(int m)
Parameters
mintThe minimum number of times to repeat the regex, inclusive.
Returns
Between(int, int)
Creates a Regex that matches this regex a number of times within a range.
public Regex Between(int m, int n)
Parameters
mintThe minimum number of times to repeat the regex, inclusive.
nintThe maximum number of times to repeat the regex, inclusive.
Returns
Exceptions
- ArgumentOutOfRangeException
mornis negative,mis greater thann, ornis equal to MaxValue.
CaseInsensitive()
Creates a case-insensitive copy of this Regex.
public Regex CaseInsensitive()
Returns
CaseSensitive()
Creates a case-sensitive copy of this Regex.
public Regex CaseSensitive()
Returns
Choice(params Regex[])
Creates a Regex that matches either one of many regexes.
public static Regex Choice(params Regex[] regexes)
Parameters
regexesRegex[]The regexes to choose form.
Returns
Remarks
Passing an empty array to regexes will result in
a regex that cannot match anything. This is usually not desirable
and will result in a build-time warning.
Choice(params ImmutableArray<Regex>)
Creates a Regex that matches either one of many regexes.
public static Regex Choice(params ImmutableArray<Regex> regexes)
Parameters
regexesImmutableArray<Regex>The regexes to choose form.
Returns
Remarks
Passing an empty array to regexes will result in
a regex that cannot match anything. This is usually not desirable
and will result in a build-time warning.
FromRegexString(string)
Creates a Regex specified by a string pattern.
public static Regex FromRegexString(string pattern)
Parameters
patternstringThe regex's pattern.
Returns
Remarks
This method will not fail if the pattern is invalid, but when the returned Regex is used to build a grammar, it will result in a build error.
Join(params Regex[])
Creates a Regex that matches many regexes in sequence.
public static Regex Join(params Regex[] regexes)
Parameters
regexesRegex[]The regexes to concatenate.
Returns
Join(params ImmutableArray<Regex>)
Creates a Regex that matches many regexes in sequence.
public static Regex Join(params ImmutableArray<Regex> regexes)
Parameters
regexesImmutableArray<Regex>The regexes to concatenate.
Returns
Literal(char)
A Regex that matches a specific character.
public static Regex Literal(char c)
Parameters
cchar
Returns
Literal(string)
A Regex that matches a specific string of characters.
public static Regex Literal(string s)
Parameters
sstring
Returns
NotOneOf(params char[])
Creates a Regex that matches all characters except of specific ones.
public static Regex NotOneOf(params char[] chars)
Parameters
charschar[]The characters to not match.
Returns
NotOneOf(IEnumerable<char>)
Creates a Regex that matches specific characters.
public static Regex NotOneOf(IEnumerable<char> chars)
Parameters
charsIEnumerable<char>The characters to match.
Returns
Remarks
Passing an empty array to chars will result in
a regex that cannot match anything. This is usually not desirable
and will result in a build-time warning.
NotOneOf(params ImmutableArray<char>)
Creates a Regex that matches all characters except of specific ones.
public static Regex NotOneOf(params ImmutableArray<char> chars)
Parameters
charsImmutableArray<char>The characters to not match.
Returns
NotOneOf(params ImmutableArray<(char Start, char End)>)
Creates a Regex that matches all characters except of those in specific ranges.
public static Regex NotOneOf(params ImmutableArray<(char Start, char End)> ranges)
Parameters
rangesImmutableArray<(char Start, char End)>The character ranges to not match, inclusive.
Returns
Exceptions
- ArgumentException
A range's start is greater than its end.
NotOneOf(params (char Start, char End)[])
Creates a Regex that matches all characters except of those in specific ranges.
public static Regex NotOneOf(params (char Start, char End)[] chars)
Parameters
Returns
Exceptions
- ArgumentException
A range's start is greater than its end.
OneOf(params char[])
Creates a Regex that matches specific characters.
public static Regex OneOf(params char[] chars)
Parameters
charschar[]The characters to match.
Returns
Remarks
Passing an empty array to chars will result in
a regex that cannot match anything. This is usually not desirable
and will result in a build-time warning.
OneOf(IEnumerable<char>)
Creates a Regex that matches specific characters.
public static Regex OneOf(IEnumerable<char> chars)
Parameters
charsIEnumerable<char>The characters to match.
Returns
Remarks
Passing an empty array to chars will result in
a regex that cannot match anything. This is usually not desirable
and will result in a build-time warning.
OneOf(params ImmutableArray<char>)
Creates a Regex that matches specific characters.
public static Regex OneOf(params ImmutableArray<char> chars)
Parameters
charsImmutableArray<char>The characters to match.
Returns
Remarks
Passing an empty array to chars will result in
a regex that cannot match anything. This is usually not desirable
and will result in a build-time warning.
OneOf(params ImmutableArray<(char, char)>)
Creates a Regex that matches characters in specific ranges.
public static Regex OneOf(params ImmutableArray<(char, char)> ranges)
Parameters
rangesImmutableArray<(char Start, char End)>An immutable array with the character ranges, inclusive.
Returns
Remarks
Passing an empty array to ranges will result in
a regex that cannot match anything. This is usually not desirable
and will result in a build-time warning.
Exceptions
- ArgumentException
A range's start is greater than its end.
OneOf(params (char Start, char End)[])
Creates a Regex that matches characters in specific ranges.
public static Regex OneOf(params (char Start, char End)[] chars)
Parameters
Returns
Remarks
Passing an empty array to ranges will result in
a regex that cannot match anything. This is usually not desirable
and will result in a build-time warning.
Exceptions
- ArgumentException
A range's start is greater than its end.
Optional()
Creates a Regex that matches this regex either once or not at all.
public Regex Optional()
Returns
Repeat(int)
Creates a Regex that matches this regex a specific number of times.
public Regex Repeat(int n)
Parameters
nintThe number of times to repeat the regex.
Returns
Exceptions
- ArgumentOutOfRangeException
nis negative, or equal to MaxValue.
ZeroOrMore()
Creates a Regex that matches this regex any number of times or not at all.
public Regex ZeroOrMore()
Returns
Remarks
This is also known as the Kleene star.
Operators
operator +(Regex, Regex)
Concatenates two Regex objects.
public static Regex operator +(Regex left, Regex right)
Parameters
Returns
- See Also
operator |(Regex, Regex)
Combines two Regex objects with an OR operator.
public static Regex operator |(Regex left, Regex right)
Parameters
Returns
- See Also