verbalexpressions / csharpverbalexpressions Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Make a Verbal Expression wizard, that helps you visually create and test the expressions validations and captures.
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
?
Project looks like dead and poor documented. Is there alternatives?
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;¶m2=val2";
var matches = verbEx.Match( testMe );
Assert.IsGreaterThan( matches.Count, 0, "The URL has no parameters");
Console.WriteLine("We have a correct URL ");
}
'''
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?
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"};
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
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?
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?
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.
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
.
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.
I was thinking that the namespace CSharpVerbalExpressions is pretty redundant and can probably be shortened to simply VerbalExpressions. What does everybody think?
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?
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
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
Is there a reason the nuget package hasn't been updated in 3 years?
Your comment for the unit tests says 82% code coverage. What coverage is missing? What kind of tests are remaining?
Hi,
I'm trying to open the VerbalExpressions.sln with VS2010.
I did the following actions:
Can this solution and projects run in VS2010?
Thanks,
Ophir
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.