I have a simple regex requirement for a route in CakePHP that is giving me trouble.
Routing code:
Router::connect('/tees/:id', array('controller' => 'tees', 'action' => 'view'), array('id' => "^.*[0-9].*[-][a-z].*$"));
regex: "^.*[0-9].*[-][a-z].*$"
Matched case: 340764-test-tee
Failed case: test
Failed case: anysingleword
Any ideas as to what I’m doing wrong?
Thank you!
EDIT:
The solution I ended up using is as follows:
".*[0-9].*[a-z-].*"
According to regex syntax you are requiring each match to include a ‘-‘ character ( the [-] in your regex) therefore any word without ‘-‘ will not match.
If you intended to do that then [-] is not the usual way, use \-
If you did NOT intend to match a ‘-‘ ALWAYS, maybe you wanted to add it to the [a-z], then the right syntax is:
But note thet [a-z-] will match only 1 character, you probably meant
or