Giter VIP home page Giter VIP logo

csharpverbalexpressions's Introduction

CSharpVerbalExpressions

CSharp Regular Expressions made easy

VerbalExpressions is a CSharp library that helps to construct difficult regular expressions.

NuGet

Install-Package VerbalExpressions-official

How to get started

When first building the solution there will be external libraries that are missing since GitHub doesn't include DLLs. The best way to get these libraries into your solution is to use NuGet. However, since the project is now using NuGet Package Restore, manually installing the packages may not be necessary. Below lists the libraries that are required if manual installing is needed.

The libraries that are needed to build are the following:

  • NUnit

Examples

Here's a couple of simple examples to give an idea of how VerbalExpressions works:

Testing if we have a valid URL

		[TestMethod]
		public void TestingIfWeHaveAValidURL()
		{
			// Create an example of how to test for correctly formed URLs
			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 ");
		}

API documentation

Coming...

Other implementations

You can view all implementations on VerbalExpressions.github.io

csharpverbalexpressions's People

Contributors

alexpeta avatar bairamovrishad avatar ccarreola avatar chrisevans9629 avatar cuongtranba avatar jehna avatar jwood803 avatar kjellski avatar metzing avatar mihai-vlc avatar psoholt avatar signpostmarv avatar thaiphan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharpverbalexpressions's Issues

Alternative?

Project looks like dead and poor documented. Is there alternatives?

Feature Suggestion: .verbex files in project -> Compiled Regex via custom tool

Some regexes can get very complex and work best as standalone compiled regex dlls.

It would be nice to have something like a .verbex file that you can include in the project the syntax would be identical to the code embeded version. then during compile a custom tool will run that will execute the code in the .verbex file and transform it into one of 2 things
either

  • a .cs file with the rendered regex ,and static methods so the developer can do a .isMatch
  • use Regex.CompileToAssembly to create an assembly useable in that project

NuGet package out of date?

It seems that there are some methods in the source code that are not included in the NuGet package? Could someone update the package in the gallery?

Honourable mention

If you are going to take someone else's code, at least fork it, don't "port" it and then stick your own MIT license on it in the next commit.

Sad

Ranges cause invalid Regex

When using the .Range method with range arrays greater than 3, it causes invalid Regex to be output. An example can be seen with the following snippet taken from a Unit test and modified:

var verbEx = VerbalExpressions.DefaultExpression;
object[] range = new object[4] { 1, 6, 7, 12 };
verbEx.Range(range);

That expression outputs [1-126-7] which is obviously invalid regex. Not sure what is supposed to happen here? Maybe throw an ArgumentException?

Matching syntax

Sorry for wasting your time and mine. I didn't read the code, and thought you don't have this.
Also misunderstood how this works. - I thought it was an alternative to regex, now I understand that its a regex builder. (Is the reverse being considered?)

Looked at the tests and saw the capture syntax which is much better than mine (BeginCapture, EndCapture).


My original comment:

Matching syntax for getting lists of text

  • Saved groups: .MatchBy

  • Grouping: Non saving groups: .MatchFor .

  • Dependency: And. Or

  • .AllThat .FirstThat .LastThat .AnyThat

  • .Is .IsNot .IsLike (wildcard syntax) .HasFormat (String.Format() syntax)

  • .HasDate( DateFormat DateSeperator ) HasTime, HasDateAndTime

  • .Until (inclusive), Before (non inclusive until) , After (starts after the found text)

  • .HasUnicode .HasAscii .Has (calls delegate with params)

    '''C#
    [TestMethod]
    public void TestingIfWeHaveAValidURL()
    {
    // Create an example of how to find the params in a RESTful url
    var verbEx = new VerbalExpressions()
    .MatchFor( name:"param code", () => {
    .AnyThat( afterOccurence: 1) // all matches after 1st param found by next match
    // this is the way to get parenthesis around a group of rules
    .MatchFor( name: "param name", () => {
    .After("?").Or.After(";")
    MatchBy( name: "param name", () => {
    .Anything.Before("=")
    });
    });
    .And.MatchFor( name: "param val", ()=>{
    .After( matchFor: "param name")
    //.Maybe(Environment.Quotemark)
    .MatchBy(name: "param val", ()=>{
    .Until.
    //Maybe(Environment.Quotemark)
    .Then(";").Or.EndOfLine;
    });
    });

        // Create an example URL
        var testMe = "https://www.google.com?param1=val1;&param2=val2";
        var matches = verbEx.Match( testMe );
        Assert.IsGreaterThan( matches.Count, 0, "The URL has no parameters");
    
        Console.WriteLine("We have a correct URL ");
    }
    

    '''

AnythingBut followed by a Maybe should be ignored

When you have an AnythingBut followed by a Maybe assuming the value of Maybe isn't the value of AnythingBut then the Maybe should be ignored.

For instance the two following are semantically the same:

var verbEx = VerbalExpressions.DefaultExpression
    .StartOfLine()
    .Then( "http" )
    .Maybe( "s" )
    .Then( "://" )
    .Maybe( "www." )
    .AnythingBut( " " )
    .EndOfLine();

 

var verbEx = VerbalExpressions.DefaultExpression
    .StartOfLine()
    .Then( "http" )
    .Maybe( "s" )
    .Then( "://" )
    .Maybe( "www." )
    .AnythingBut( " " )
            .Maybe("/")
    .EndOfLine();

Both of the above should output ^(http)(s)?(://)(www\.)?([^\ ]*)$ because the AnythingBut is greedy and will capture whatever is in the Maybe.

VerbEx spec across languages?

@VerbalExpressions

Hey guys.

I love VerbalExpression and the idea of having an easy language to read/write for RegEx. There's now ports of VerbEx to several languages. We should try to keep the VerbEx language as equal as possible across the different ports.

Should we have a specification of names for the words/functions in verbex that should be implemented across the different languages?

Why I'm asking this is because I want to implement default regex expressions, for example for e-mail or url. So I'm thinking for CSharp one can write VerbEx something like one of the:

new VerbalExpressions().StartOfLine()
.MaybeEmailAdress()
.EndOfLine();

or

new VerbalExpressions().StartOfLine()
.AnythingBut(VerbEx.Email)
.EndOfLine();

It's important that if we make something like default regex words like e-mail and url, that the underlying regex is equal between the different language ports. How do we synchronize this best? Create a specification?

Help!

Like the look of this lib but was wondering how I could produce something like this:

/(?<age>[\d]{1,2})

That way I can use it in a Nancy route definition like so:

Get["/(?<age>[\d]{1,2})"] = parameters => {"Hello World"};

Not available via NuGet

Hey there,

with my last Pull Request, you should've merged everything necessary in to deploy this as a NuGet Package to be available via NuGet. I'm just interested in how to publish something to NuGet gallery for public. If you're going to do so, please let me know how it went.

Issue: CSharpVerbalExpressions is not available via NuGet.

Greetings,
Kjellski

P.S.: I've prefilled the VerbalExpressions\VerbalExpressions.nuspec with values, feel free to change it accordingly.

VerbalExpression Performance Question

Hi all,
I ran the following test to check how well verbal expression performs compared to a regular expression:

    [Test]
    public void TestingIfWeHaveAValidURL()
    {
        var testMe = "https://www.google.com";

        var swVerb = new Stopwatch();
        swVerb.Start();
        verbEx = VerbalExpressions.DefaultExpression
                    .StartOfLine()
                    .Then("http")
                    .Maybe("s")
                    .Then("://")
                    .Maybe("www.")
                    .AnythingBut(" ")
                    .EndOfLine();


        Assert.IsTrue(verbEx.Test(testMe), "The URL is incorrect");
        swVerb.Stop();

        var swRegex = new Stopwatch();
        swRegex.Start();
        var regex = new Regex( @"^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$" );
        Assert.IsTrue( regex.IsMatch( testMe ) );
        swRegex.Stop();
        //Verb: 133 ms Regex: 4 ms
        Console.WriteLine("Verb: {0}   Regex: {1}", swVerb.ElapsedMilliseconds, swRegex.ElapsedMilliseconds);
    }

I ran it a couple of times and verbal expression runs at about 130 milliseconds, while regular expression runs in about 5 ms.

Same results returned in other tests I did.
I'm considering using the verbal expression in my indexing project, so this time gap is too big.
What do you think?

Thanks

New release to nuget

Hi there!
Our team is looking at this package to help us build our regular expressions. Will there be a new release to nuget anytime soon? If not, can we set up a CI/CD pipeline to build new releases?

Nuget Package

Is there a reason the nuget package hasn't been updated in 3 years?

Opening with VS 2010

Hi,

I'm trying to open the VerbalExpressions.sln with VS2010.
I did the following actions:

  1. Changed the solution file to VS2010.
  2. Changed the projects framework to v4.0.
  3. Downloaded and installed the Portable Class Library.
    Now the solution and projects open but I can't run the unit testing and some strange things happen:
    System.Text.RegularExpressions is not identified at VerbalExpressions project.
    The VerbalExpressions project has no References and it is not possible to add references to it.

Can this solution and projects run in VS2010?

Thanks,
Ophir

Change the namespace

I was thinking that the namespace CSharpVerbalExpressions is pretty redundant and can probably be shortened to simply VerbalExpressions. What does everybody think?

Suggestions and Improvements

Hi, I admire your work, and these are some suggestions:
1- Add "Const" as another name to "Then"
2- Add another overload to AnyOf that accepts Char Array, because it's more friendly.

 public VerbalExpressions AnyOf(char[] value, bool sanitize = true)
        {
            if (value == null)
                throw new ArgumentNullException("value");

            return AnyOf(string.Join ("", value));
        }

3- Range Method can be more friendly like this:
Range(char start, char end);
Range(int start, int end);

4- A Repeat(string Valuem, int min, int max) will be useful , and A Repeat(VerbalExpressions expr, int min, int max ) will be more friendly than BeginCapture/EndCapture/RepeatPrevious, besides RepeatPrevious(int min, int max)

5- Need some methods without parameters such as Letter(), UpperCaseLetter(), LowerCaseLetter(), Digit(), Boundry() and other famous formulas.

6- All Repetition methods needs optional param. for laziness.

5- Where Are LookAhead(), LookBehind( ), Atomic(VerbalExpressions Exp1)?

7- Add If(VerbalExpressions expr, VerbalExpressions expr1, VerbalExpressions expr2) to imo;ement regex conditions.

Optional parameters

There are many methods which use overload with bool enable. In those cases we could set it as an optional parameter, which would reduce methods.

Why is that, is this a coding style guideline? Can it be replaced?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.