Typified help in building regular expressions pattern.
Typified C# Regular Expressions Pattern.
TypeRegex is a CSharp library that helps to construct regular expressions patterns reducing typos and other common mistakes.
Use the package manager NuGet to install TypeRegex.
Install-Package TypeRegex
using TypeRegex;
public class Program
{
public static void Main()
{
var pattern = new Pattern()
.AtStartOfStringOnly()
.Any()
.NewLine(true)
.AtEndOfStringOnly();
Console.Write(pattern);
// The example displays the following output:
// "\A[\u0000-\uFFFF]\u000D?\u000A\z"
}
};
Character or sequence | Description | TypeRegex |
---|---|---|
\a |
Alarm character, \u0007 . |
Pattern.Alarm() , Escapes.Alarm |
\a |
Bell character, \u0007 . |
Pattern.Bell() , Escapes.Bell |
\b |
Backspace, \u0008 . |
Pattern.Backspace() , Escapes.Backspace |
\t |
Tab, \u0009 . |
Pattern.Tab() , Escapes.Tab |
\r |
Carriage return, \u000D . |
Pattern.CarriageReturn() , Escapes.CarriageReturn |
\v |
Vertical tab, \u000B . |
Pattern.VerticalTab() , Escapes.VerticalTab |
\f |
Form feed, \u000C . |
Pattern.FormFeed() , Escapes.FormFeed |
\n |
New line, \u000A . |
Pattern.NewLine() , Escapes.NewLine |
\e |
Escape, \u001B . |
Pattern.Escape() , Escapes.Escape |
\r?\n |
Zero or one occurrence of a carriage return followed by a new line, \u000D?\u000A . |
Pattern.NewLine(true) , Escapes.WindowsNewLine |
\ nnn |
ASCII character with octal code. | Pattern.Octal(string octalNumber) |
\x nn |
ASCII character with hexadecimal code. | Pattern.Hexadecimal(string hexadecimalNumber) |
\c X |
ASCII control character. | Pattern.ASCIIControl(string controlCharacter) |
\u nnnn |
UTF-16 code unit with hexadecimal value. | Pattern.Unicode(string hexadecimal) |
\ |
Escapes the followed character. | Pattern.Literal(char character) |
Syntax | Description | TypeRegex |
---|---|---|
[character_group] |
Positive character group. | Pattern.AnyIn(string set, bool escape = true) new PositiveCharacterGroup(string set, bool escape = true) |
[character_group] |
Pattern.AnyIn(params char[] set) new PositiveCharacterGroup(params char[] set) |
|
[firstCharacter-lastCharacter] |
Pattern.Range(char first, char last, bool caseSensitive = true) new PositiveCharacterGroup(char first, char last, bool caseSensitive = true) |
|
[firstCharacter-lastCharacter] |
Pattern.Range(uint first, uint last) new PositiveCharacterGroup(uint first, uint last) |
|
[^character_group] |
Negative character group. | Pattern.AnyNotIn(string set, bool escape = true) new NegativeCharacterGroup(string set, bool escape = true) |
[^character_group] |
Pattern.AnyNotIn(params char[] set) new NegativeCharacterGroup(params char[] set) |
|
[^firstCharacter-lastCharacter] |
Pattern.NotInRange(char first, char last, bool caseSensitive = true) new NegativeCharacterGroup(char first, char last, bool caseSensitive = true) |
|
[^firstCharacter-lastCharacter] |
Pattern.NotInRange(uint first, uint last) new NegativeCharacterGroup(uint first, uint last) |
|
. |
Any character | Pattern.Any() new PositiveCharacterGroup() |
\p{name} |
Unicode Category | Pattern.Add(UnicodeGroup{PositiveUnicodeCategory}.ToString()) Pattern.UnicodeGroup(UnicodeGroup{PositiveUnicodeCategory} group) |
\p{name} |
Unicode Block | Pattern.Add(UnicodeGroup{PositiveUnicodeBlock}.ToString()) Pattern.UnicodeGroup(UnicodeGroup{PositiveUnicodeBlock} group) |
\P{name} |
Negative Unicode Category | Pattern.Add(UnicodeGroup{NegativeUnicodeCategory}.ToString()) Pattern.UnicodeGroup(UnicodeGroup{NegativeUnicodeCategory} group) |
\P{name} |
Negative Unicode Block | Pattern.Add(UnicodeGroup{NegativeUnicodeBlock}.ToString()) Pattern.UnicodeGroup(UnicodeGroup{NegativeUnicodeBlock} group) |
\w |
Word character | Pattern.Word(MatchingBehavior matchingBehavior = MatchingBehavior.Default) Pattern.ECMAScriptWord() Pattern.UnicodeWord() |
\W |
Non-word character | Pattern.NonWord(MatchingBehavior matchingBehavior = MatchingBehavior.Default) Pattern.ECMAScriptNonWord() Pattern.UnicodeNonWord() |
\s |
Whitespace character | Pattern.WhiteSpace(MatchingBehavior matchingBehavior = MatchingBehavior.Default) Pattern.ECMAScriptWhiteSpace() Pattern.UnicodeWhiteSpace() |
\S |
Non-whitespace character | Pattern.NonWhiteSpace(MatchingBehavior matchingBehavior = MatchingBehavior.Default) Pattern.ECMAScriptNonWhiteSpace() Pattern.UnicodeNonWhiteSpace() |
\d |
Decimal digit character | Pattern.Digit(MatchingBehavior matchingBehavior = MatchingBehavior.Default) Pattern.ECMAScriptDigit() Pattern.UnicodeDigit() |
\D |
Non-digit character | Pattern.NonDigit(MatchingBehavior matchingBehavior = MatchingBehavior.Default) Pattern.ECMAScriptNonDigit() Pattern.UnicodeNonDigit() |
[base_group - [excluded_group]] |
Character class subtraction | Pattern.Subtraction(ISubtractable baseGroup, CharacterGroup excludedGroup) |
Coming soon
Coming soon
Coming soon
Coming soon
Coming soon
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.