Table of Contents

Class Regex

Namespace
Farkle.Builder
Assembly
Farkle.dll

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

Regex

Empty

A Regex that matches the empty string.

public static Regex Empty { get; }

Property Value

Regex

Methods

AtLeast(int)

Creates a Regex that matches this regex at least a specific number of times.

public Regex AtLeast(int m)

Parameters

m int

The minimum number of times to repeat the regex, inclusive.

Returns

Regex

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 int

The minimum number of times to repeat the regex, inclusive.

n int

The maximum number of times to repeat the regex, inclusive.

Returns

Regex

Exceptions

ArgumentOutOfRangeException

m or n is negative, m is greater than n, or n is equal to MaxValue.

CaseInsensitive()

Creates a case-insensitive copy of this Regex.

public Regex CaseInsensitive()

Returns

Regex

CaseSensitive()

Creates a case-sensitive copy of this Regex.

public Regex CaseSensitive()

Returns

Regex

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

Regex

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

Regex

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 string

The regex's pattern.

Returns

Regex

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

Regex

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

Regex

Literal(char)

A Regex that matches a specific character.

public static Regex Literal(char c)

Parameters

c char

Returns

Regex

Literal(string)

A Regex that matches a specific string of characters.

public static Regex Literal(string s)

Parameters

s string

Returns

Regex

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

Regex

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

Regex

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

Regex

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

Regex

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

chars (char Start, char End)[]

Returns

Regex

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

Regex

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

Regex

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

Regex

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

Regex

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

chars (char Start, char End)[]

Returns

Regex

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

Regex

Repeat(int)

Creates a Regex that matches this regex a specific number of times.

public Regex Repeat(int n)

Parameters

n int

The number of times to repeat the regex.

Returns

Regex

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

Regex

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

left Regex

The first regex.

right Regex

The second regex.

Returns

Regex

A Regex that matches left and then right in sequence.

See Also

operator |(Regex, Regex)

Combines two Regex objects with an OR operator.

public static Regex operator |(Regex left, Regex right)

Parameters

left Regex

The first regex.

right Regex

The second regex.

Returns

Regex

A Regex that matches either left or right.

See Also