Skip to content

anyOf is not matched requirements #59

Open

Description

@dawnbreaks

How can JavaVerbalExpressions build a simple regex like this: [\d,]+

VerbalExpression.regex().anyOf("0123456789,").oneOrMore().build()

It 's too ugly! How about this one: [a-k\s\d,]+ ?

It would be nice to add a anyOf method that can used like this:

VerbalExpression.regex().anyOf(DigitCharSet, WordCharSet, SpaceCharSet ,";:,\\").oneOrMore().build()

Activity

  1. lanwen commented on May 23, 2017

    @lanwen
    Contributor

    Can't see why your variant better than original

  2. dawnbreaks commented on May 24, 2017

    @dawnbreaks
    Author

    @lanwen It 's ridiculous to list all the Word char and all digit char in the sring parameter in the anyOf method.

  3. lanwen commented on May 24, 2017

    @lanwen
    Contributor

    lib already has .wordChar().nonWordChar().space().nonSpace().digit().nonDigit()

    use with .capture().endCapture() - is it solve your case?

  4. dawnbreaks commented on May 24, 2017

    @dawnbreaks
    Author

    No. Please tell me how to use verbalExpressions to represent this regex: [a-k\s\d,]+

  5. lanwen commented on May 24, 2017

    @lanwen
    Contributor

    regex().add("[").wordChar().space().digit().add("]").oneOrMore()

    regex().anyOf("\\w\\s\\d")

    regex().capture().digit().or("\\w").or("\\s").endCapture().oneOrMore()

    regex().add("[a-k\s\d,]+")

    You can use raw regex if it looks more compact

  6. dawnbreaks commented on May 24, 2017

    @dawnbreaks
    Author

    I think java regex is more readable than verbal expressions. VE is too awkward to use it.

  7. lanwen commented on May 24, 2017

    @lanwen
    Contributor

    In some cases it's true! VE is mostly for those who don't know how to type simple regex. Or where you should write something that should be human-readable (for example in tests).

  8. eduardohmg commented on Jul 18, 2017

    @eduardohmg

    It's some late, but I think with an indentation it can be better:

    .add("[")
    .wordChar().space().digit()
    .add("]")
    .oneOrMore()
    

    You are right, sometimes regex is better than ve, principally for those who know regex enough. But we have a lot of thing to improve our code, whatever we use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions