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

Use Character-Enum without CharacterIn? #2

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

Use Character-Enum without CharacterIn? #2

Birgos opened this issue Jun 26, 2015 · 3 comments

Comments

@Birgos
Copy link

Birgos commented Jun 26, 2015

Following expression: (?<First>(?:2[0-4]\d|25[0-5]|[01]?\d\d?))\.(?<Second>(?:2[0-4]\d|25[0-5]|[01]?\d\d?))\.(?<Third>(?:2[0-4]\d|25[0-5]|[01]?\d\d?))\.(?<Fourth>(?:2[0-4]\d|25[0-5]|[01]?\d\d?))

My result:

var ipAdress = new Magex().Alternative(
    Magex.New()
              .Character('2')
              .CharacterIn('0', '-', '4')
              .CharacterIn(Characters.Numeral),
    Magex.New()
              .String("25")
              .CharacterIn('0', '-', '5'),
    Magex.New()
              .CharacterIn('0', '1').Repeat.AtMostOnce()
              .CharacterIn(Characters.Numeral)
              .CharacterIn(Characters.Numeral).Repeat.AtMostOnce());

var expression = new Magex().CaptureAs("First", _ipAdress)
   .Character('.')
   .CaptureAs("Second", ipAdress)
   .Character('.')
   .CaptureAs("Third", ipAdress)
   .Character('.')
   .CaptureAs("Fourth", ipAdress);

Is there a way to use the enums of Characters directly without encapsulating them inside a CharacterIn call? Getting \d instead of [\d]?

@ghusse
Copy link
Owner

ghusse commented Jun 26, 2015

You have to replace .CharacterIn(Characters.Numeral) by .Character(Characters.Numeral)

@Birgos
Copy link
Author

Birgos commented Jun 26, 2015

That doesn't work for me. Error message:
Argument type 'MagicExpression.Characters' is not assignable to parameter type 'char'

Timothep added a commit that referenced this issue Jul 1, 2015
@Timothep
Copy link
Collaborator

Timothep commented Jul 1, 2015

The option to use enums in the Character() function was not yet coded. I just pushed a new commit to the repo that passes your test.
Please checkout the newest version of the repo to see the update.

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

3 participants