CSharpVerbalExpressions is a library for .NET that helps us build complex regular expressions (regex) in a simpler way.
This library is the C# version of the popular JavaScript VerbalExpressions library. This project is dedicated to providing a simpler syntax style for using regular expressions.
VerbalExpressions uses a string-based approach to build regular expressions. Instead of writing a regular expression directly, we build a regular expression step by step using the library’s methods.
These methods have meaningful names like ‘Then’ or ‘Maybe’, which makes the code easier to read and understand. Thanks to VerbalExpressions, writing regex is much simpler.
Later, we can apply the VerbalExpressions to the dataset we want to work on, or generate the RegEx directly.
How to use CSharpVerbalExpressions
We can easily add the library to a .NET project through the corresponding Nuget package.
Install-Package VerbalExpressions-official
Here are some examples of how to use CSharpVerbalExpressions extracted from the library’s documentation.
var verbEx = new VerbalExpressions()
.StartOfLine()
.Then( "http" )
.Maybe( "s" )
.Then( "://" )
.Maybe( "www." )
.AnythingBut( " " )
.EndOfLine();
// Create an example URL
var testMe = "https://www.google.com";
Assert.IsTrue(verbEx.Test( testMe ), "The URL is incorrect");
Console.WriteLine("We have a correct URL ");
CSharpVerbalExpressions is Open Source, and all the code and documentation is available in the project repository at https://github.com/VerbalExpressions/CSharpVerbalExpressions

