CSharpVerbalExpressions icon indicating copy to clipboard operation
CSharpVerbalExpressions copied to clipboard

AnythingBut followed by a Maybe should be ignored

Open jduncanator opened this issue 11 years ago • 0 comments

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.

jduncanator avatar Aug 30 '13 09:08 jduncanator