FluentRegex

IBuilder

Namespace: FluentRegex

Interface IBuilder defines the methods and properties for building a regular expression pattern.

public interface IBuilder

Properties

Pattern

Gets or sets the pattern.

public abstract StringBuilder Pattern { get; set; }

Property Value

StringBuilder

Methods

Build()

Builds the regular expression pattern.

object Build()

Returns

Object

ToString()

Returns the regular expression pattern as a string.

string ToString()

Returns

String

AppendLiteral(String)

The AppendLiteral method appends a literal string to the pattern, escaping any special characters.

object AppendLiteral(string literal)

Parameters

literal String

Returns

Object

Validate()

Validates the pattern to ensure it is well-formed. Each validation method contains explicit error messages which are thrown when the validation fails. This should help the user to understand what is wrong with the pattern, rather than just throwing a generic exception. However the final validation method checks that the pattern is a valid regular expression, and throws a generic exception if it is not, bubbling up the error message from the regular expression engine.

void Validate()

Validate(Boolean)

Validates the pattern to ensure it does not end with any characters that would cause an exception when building the regular expression. Allows the user to skip the regular expression validation.

void Validate(bool skipRegexValidation)

Parameters

skipRegexValidation Boolean
A Boolean value to skip the regular expression validation.

ValidateEnd()

Validates the pattern to ensure it does not end with any characters that would cause an exception when building the regular expression.

void ValidateEnd()

ValidateStart()

Validates the pattern to ensure it does not start with any characters that would cause an exception when building the regular expression.

void ValidateStart()

Exceptions

InvalidOperationException

ValidateParenthesesPairs()

Validates the pattern to ensure that the number of opening and closing parentheses match.

void ValidateParenthesesPairs()

Exceptions

InvalidOperationException

ValidateNoEmptyStructures()

Validates the pattern to ensure it does not contain empty structures. Including empty parentheses, empty non-capturing groups, and empty named capturing groups, empty Character classes.

void ValidateNoEmptyStructures()

ValidateNoUnEscapedCharacters()

Validates the pattern to ensure there are no unescaped characters that are not escapable.

void ValidateNoUnEscapedCharacters()

GetOpenCloseCharacterCounts()

Dictionary<char, int> GetOpenCloseCharacterCounts()

Returns

Dictionary<Char, Int32>

GetCountOfCharacter(Char, String)

int GetCountOfCharacter(char character, string pattern)

Parameters

character Char

pattern String

Returns

Int32

OpenClosingCharacterCountsMatch(String)

bool OpenClosingCharacterCountsMatch(string pattern)

Parameters

pattern String

Returns

Boolean

ParenthesesCountsAreEven()

bool ParenthesesCountsAreEven()

Returns

Boolean

SquareBracketCountsAreEven()

bool SquareBracketCountsAreEven()

Returns

Boolean

CurlyBraceCountsAreEven()

bool CurlyBraceCountsAreEven()

Returns

Boolean

CheckInvalidEscapedClosure(String, Char[])

void CheckInvalidEscapedClosure(string pattern, Char[] closingCharacters)

Parameters

pattern String

closingCharacters Char[]

ValidatePatternRegex()

Validates the pattern to ensure it is a valid regular expression.

void ValidatePatternRegex()