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

anyOf is not matched requirements #59

Open
dawnbreaks opened this issue May 22, 2017 · 8 comments
Open

anyOf is not matched requirements #59

dawnbreaks opened this issue May 22, 2017 · 8 comments

Comments

@dawnbreaks
Copy link

dawnbreaks commented May 22, 2017

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()
@lanwen
Copy link
Contributor

lanwen commented May 23, 2017

Can't see why your variant better than original

@dawnbreaks
Copy link
Author

dawnbreaks commented May 24, 2017

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

@lanwen
Copy link
Contributor

lanwen commented May 24, 2017

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

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

@dawnbreaks
Copy link
Author

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

@lanwen
Copy link
Contributor

lanwen commented May 24, 2017

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

@dawnbreaks
Copy link
Author

dawnbreaks commented May 24, 2017

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

@lanwen
Copy link
Contributor

lanwen commented May 24, 2017

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).

@eduardohmg
Copy link

eduardohmg commented Jul 18, 2017

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants