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

Exact digits matching #6

Closed
TomasVotruba opened this issue Feb 26, 2015 · 3 comments
Closed

Exact digits matching #6

TomasVotruba opened this issue Feb 26, 2015 · 3 comments
Labels

Comments

@TomasVotruba
Copy link
Contributor

I'm trying to match expression with exactly 10 digits. Maybe I don't understand it correctly, so here is my example:

$regExp = (new RegExpBuilder)->exactly(10)->digits()->getRegExp();

var_dump($regExp->test(123456789)); // should: FALSE, is FALSE
var_dump($regExp->test(1234567890)); // should: TRUE, is TRUE
var_dump($regExp->test(12345678901)); // should: FALSE, is TRUE

How to achieve my goal?

@gherkins
Copy link
Owner

the third example is still valid as it still contains 10 digits.

$regExp = (new RegExpBuilder)
                  ->startOfInput() //expect start of input before digits
                  ->exactly(10)->digits() 
                  ->endOfInput() //expect end of input after digits
                  ->getRegExp();

should do the trick

@gherkins
Copy link
Owner

updated, missed the startOfInput() call. Otherwise you would still have 10digits, then endOfInput...

@TomasVotruba
Copy link
Contributor Author

Works like a charm! Thank you.

Btw, great idea for a library. So much helpful!

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

No branches or pull requests

2 participants