Skip to content

Regular Expressions Library

VerbalExpressions


Description

A library that helps construct difficult regular expressions in natural language, using common verbs and terms instead of unfriendly character sequences

Methods

IsEmail(string)

Description

Checks whether the value of the input parameter represents a valid e-mail address or not.

Return Type : bool

Static : Yes

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The string to check

Syntax

if(RegExpLib.VerbalExpressions.IsEmail("someone@email.com") == false){
    ShowMessage("Please, enter a valid e-mail address");
}



IsUrl(string)

Description

Checks whether the value of the input paramenter represents a valid URL or not.

Return Type : bool

Static : Yes

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The string to check

Syntax

if(RegExpLib.VerbalExpressions.IsUrl("https://www.zappdev.com") == false){
    ShowMessage("Please, enter a valid URL.");
}



StringMatchesPattern(string, string)

Description

Checks whether the string passed as an input parameter matches the specified pattern

Return Type : bool

Static : Yes

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The string to be checked
pattern string The pattern to be applied

Syntax

string email = "someone@email.com";
string emailPattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}";
if(RegExpLib.VerbalExpressions.StringMatchesPattern(email, emailPattern)){
    ShowMessage("Please, enter a valid e-mail address.");
}



StartOfLine()

Description

Make the expression start at the beginning of the line

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Syntax

RegExpLib.VerbalExpressions expressions;
expressions = expressions.StartOfLine().Then("apple").Anything();
DebugLib.Logger.Assert(expressions.IsMatch("apple"), "The line starts with [apple]");
DebugLib.Logger.Assert(!expressions.IsMatch("pineapple"), "The line does not start with [apple]");



EndOfLine()

Description

Mark the expression to end at the last character of the line

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Syntax

RegExpLib.VerbalExpressions expressions;
string lorem = "Lorem ipsum\n Dolor sit amet.";
lorem = expressions.EndOfLine().Replace(lorem, "<br/ >"); 
//Outputs: Lorem ipsum<br /> Dolor sit amet. <br/>



Anything()

Description

Adds zero or more expressions that result from the previous rule

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Syntax

RegExpLib.VerbalExpressions expressions;
expressions = expressions.StartOfLine().Then("apple").Anything();



Something()

Description

Adds one or more expressions that result from the previous rule

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Syntax

RegExpLib.VerbalExpressions expressions;
expressions = expressions.StartOfLine().Then("apple").Something();



Then(string)

Description

Finds and adds the requested string in the expression

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The string to be looked for

Syntax

RegExpLib.VerbalExpressions expressions;
expressions = expressions.StartOfLine().Then("apple").Anything();



Maybe(string)

Description

Adds a string to the expression, that might appear zero or one times

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The string to be looked for

Syntax

RegExpLib.VerbalExpressions expressions;
string greeting = "Hello, my name is Mr. Slim Shady";
bool isMister = expressions.Maybe("Mr.").Maybe("Mister").IsMatch(greeting);



Or(string)

Description

Adds an alternative expression to be matched

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The string to be looked for

Syntax

RegExpLib.VerbalExpressions expressions;
string link = "http:////www.zappdev.com";
//Is link if starts with http, maybe with https, or ftp
bool isLink = expressions.Then("http").Maybe("s").Then(":").Or("ftp:////").IsMatch(link);



AnythingBut(string)

Description

Adds any string except for the one passed as the parameter. Might add nothing

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The string to be avoided

Syntax

RegExpLib.VerbalExpressions expressions;
string sqlSelect = "SELECT Id, Name, Surname FROM Users";
if(expressions.AnythingBut("Id").IsMatch(sqlSelect) == false){
    ShowMessage("The query has so much more than an Id!");
}



SomethingBut(string)

Description

Adds one or more strings that do not match the value passed as the parameter

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The string to be avoided

Syntax

RegExpLib.VerbalExpressions expressions;
string sqlSelect = "SELECT Id, Name, Surname, ParentId FROM Users";
if(expressions.AnythingBut("Id").IsMatch(sqlSelect) == false){
    ShowMessage("The query will retrieve at least one Id!");
}



LineBreak()

Description

Adds the line break expression ( )

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Syntax

RegExpLib.VerbalExpressions expressions;
string lorem = "Lorem ipsum \r\n dolor sit amet \r\n";
lorem = expressions.LineBreak().Replace(lorem, "<br />");



Tab()

Description

Adds the tab character expression ( )

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Syntax

RegExpLib.VerbalExpressions expressions;
string lorem = "Lorem ipsum\t dolor sit amet\t";
lorem = expressions.Tab().Replace(lorem, "     ");



Word()

Description

Adds an expresion that matches a whole word

Return Type : RegExpLib.VerbalExpressions

Static : No

Namespace : RegExpLib.VerbalExpressions

Syntax

RegExpLib.VerbalExpressions expressions;
string s = "I love apples, but hate pineapples";
if(expressions.Anything().Then("apples").Word().IsMatch(s)){
    ShowMessage("Found the word 'apples'! ");
}



IsMatch(string)

Description

Checks whether the string matches the pattern passed as a parameter

Return Type : bool

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
value string The pattern to be looked for

Syntax

RegExpLib.VerbalExpressions expressions;
string s = "I love apples, but hate pineapples";
if(expressions.Anything().Then("apples").Word().IsMatch(s)){
    ShowMessage("Found the word 'apples'! ");
}



Replace(string, string)

Description

In a specified input string replace everything matched, with the replacement

Return Type : string

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
Input string The string to be altered
Replacement string The value with which all found inputs should be altered

Syntax

RegExpLib.VerbalExpressions expressions;
string lorem = "Lorem ipsum \r\n dolor sit amet \r\n";
lorem = expressions.LineBreak().Replace(lorem, "<br />");



GetMatch(string)

Description

Executes the Verbal Expression against the supplied input and retrieves a single string that matches the expression. Throws a System.Exception, should anything go wrong.

Return Type : string

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
input string The string that contains the expression to be matched

Syntax

RegExpLib.VerbalExpressions expressions;
string sqlSelect = "SELECT Id, Name, Surname FROM Users";
string anythingButId = expressions.AnythingBut("Id").GetMatch(sqlSelect);
ShowMessage(anythingButId); //Shows 'SELECT' 



GetMatch(string, string)

Description

Executes the Verbal Expression against the supplied input and retrieves a single string that matches the expression. Should anything go wrong (an exception is thrown, the pattern cannot be constructed etc.), all exceptions are suppressed and the defaultValue is returned as the match.

Return Type : string

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
input string The string that contains the expression to be matched
defaultValue string The default value to be returned, should anything go wrong

Syntax

RegExpLib.VerbalExpressions expressions;
string sqlSelect = "SELECT Id, Name, Surname FROM Users";

//Here, our expression contains nothing (no verb). It will throw an exception
string noExpression = expressions.GetMatch(sqlSelect, "Something went horribly wrong...");
ShowMessage(noExpression); //Shows the default value 'Something went horribly wrong...'                      



GetMatches(string)

Description

Executes the Verbal Expression against the supplied input and retrieves all strings that match the expression. Throws a System.Exception, should anything go wrong.

Return Type : Collection

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
input string The string that contains the expression to be matched

Syntax

RegExpLib.VerbalExpressions expressions;
string sqlSelect = "SELECT Id, Name, Surname FROM Users";

Collection[string] anythingButId = expressions.AnythingBut("SELECT Id, Name, Surname FROM Users").GetMatches(sqlSelect);
string result = string.Join( ", ", anythingButId);

ShowMessage(result); //Shows 'SELECT'                                



GetMatches(string, Collection[string])

Description

Executes the Verbal Expression against the supplied input and retrieves all strings that match the expression. Should anything go wrong (an exception is thrown, the pattern cannot be constructed etc.), all exceptions are suppressed and the defaultValue is returned as the matches.

Return Type : Collection

Static : No

Namespace : RegExpLib.VerbalExpressions

Parameters

Name Data Type Description
input string The string that contains the expression to be matched
defaultValues Collection The default matches list to be returned, should anything go wrong

Syntax

RegExpLib.VerbalExpressions expressions;

string sqlSelect = "SELECT Id, Name, Surname FROM Users";

Collection[string] defaultValues;
defaultValues.Add("SELECT");
defaultValues.Add("FROM");
Collection[string] anythingButId = expressions.GetMatches(sqlSelect, defaultValues);

string result = string.Join( ", ", anythingButId);

ShowMessage(result); //Shows 'SELECT, FROM'