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
m
intThe 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
m
intThe minimum number of times to repeat the regex, inclusive.
n
intThe maximum number of times to repeat the regex, inclusive.
Returns
Exceptions
- ArgumentOutOfRangeException
m
orn
is negative,m
is greater thann
, orn
is 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
regexes
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.
Choice(params ImmutableArray<Regex>)
Creates a Regex that matches either one of many regexes.
public static Regex Choice(params ImmutableArray<Regex> regexes)
Parameters
regexes
ImmutableArray<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
pattern
stringThe 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
regexes
Regex[]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
regexes
ImmutableArray<Regex>The regexes to concatenate.
Returns
Literal(char)
A Regex that matches a specific character.
public static Regex Literal(char c)
Parameters
c
char
Returns
Literal(string)
A Regex that matches a specific string of characters.
public static Regex Literal(string s)
Parameters
s
string
Returns
NotOneOf(params char[])
Creates a Regex that matches all characters except of specific ones.
public static Regex NotOneOf(params char[] chars)
Parameters
chars
char[]The characters to not match.
Returns
NotOneOf(IEnumerable<char>)
Creates a Regex that matches specific characters.
public static Regex NotOneOf(IEnumerable<char> chars)
Parameters
chars
IEnumerable<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
chars
ImmutableArray<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
ranges
ImmutableArray<(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
chars
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(IEnumerable<char>)
Creates a Regex that matches specific characters.
public static Regex OneOf(IEnumerable<char> chars)
Parameters
chars
IEnumerable<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
chars
ImmutableArray<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
ranges
ImmutableArray<(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
n
intThe number of times to repeat the regex.
Returns
Exceptions
- ArgumentOutOfRangeException
n
is 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