Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for special groups? #1

Open
Birgos opened this issue Jun 26, 2015 · 2 comments
Open

Support for special groups? #1

Birgos opened this issue Jun 26, 2015 · 2 comments

Comments

@Birgos
Copy link

Birgos commented Jun 26, 2015

Hello,

after trying this framework i missed the support for the following special group functionality:

  • Balancing Group )?)
  • Match suffix but exclude it (?=)
  • Match prefix but exclude it (?<=)
  • Match if suffix is not present (?!)
  • Match if prefix is not present (?<!)
  • Greedy subexpression (?>)
  • Comment (?#)

Example regex expression that i wanted to rewrite:
^(?!.*[\.]{2,}.*)[a-zA-Z0-9_%\&amp;ß'+-]+((([a-zA-Z0-9_%.\&amp;ß'+-]))*[a-zA-Z0-9_%\&amp;ß'+-]+)?@(?:[a-zA-Z0-9üöäÜÖÄ-]+\.)+[a-zA-Z]{2,4}$

@Timothep
Copy link
Collaborator

Timothep commented Jul 1, 2015

Hi Birgos, good ideas! I am not sure how to beam it into the language in an elegant manner though. I don't think adding new high-level functions like BalancingGroup() would be a good idea. What about using some kind of options like the following?

magicWand.Group(x => x, GroupOptions.ExcludePrefix);

//Snip
enum GroupOptions
{
  Balancing = 0,
  ExcludeSuffix,
  ExcludePrefix,
  MatchMissingSuffix,
  MatchMissingPrefix,
  GreedySubexpression,
  Comment
}

I'm not so up to date with those constructs, can they be combined with named groups and other "elaborated" functions just with standard groups?

@Birgos
Copy link
Author

Birgos commented Jul 6, 2015

Hi!
I think the code would be easier to read if the groups were not encapsulated inside the standard group with GroupOptions. My thoughts would be something like:

 [Test]
 public void MagicExpression_SpecialGroups()
 {
    const string regExpression = @"^(?!.*[\.]{2,}.*)$";
    var result = magicExpression
       .StartOfLine()
       .MatchIfSuffixIsAbsent(x => x.Character().Repeat.Any()
           .CharacterIn('\\', '.') // produces multiple backslashes? should be equal to [\.]
               .Repeat.Between(2) // here we would need an overload to accept missing parameter
           .Character().Repeat.Any()
           .EndOfLine());
    Assert.That(result.Expression.ToString(), Is.EqualTo(regExpression));
  }

Sometimes I have used the following tool for deciphering. Maybe you can have a look? (http://www.ultrapico.com/expresso.htm)

Sorry, but unfortunately, I have not properly understood your last question :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants