Support the ongoing development of →
Requests Views Configuration
Last updated 1 year ago.

mcraz, you are correct. The URL's I typed were to illustrate my intended effect, I should have been a bit more cohesive with my example. I have corrected the URL's in my original post to reflect my example route. Thanks!

Any ideas?

Last updated 1 year ago.
0 suggests that your regex is incorrect.

Did you mean to escape the last / before the question mark?

Last updated 1 year ago.

meigwilym, good catch. Interesting though, because it works (with the exception of the 18th character). With the regex updated to: ([-a-zA-Z0-9]+/?)* which now passes regex101, it still has the same 18th character issue....

I appreciate the help! Any other ideas?

Last updated 1 year ago.


I test your problem and i see error

Try this code

Route::pattern('cat', '[A-Za-z0-9+_-]+');
Route::get('test/{cat}/{slug}', function($cat, $slug) {

    return "cat: " . $cat . " slug: " . $slug;



Route::any('test/{cat}/{slug}', function($cat,$slug){
    echo $cat;
    echo $slug;

I think problem at


Have fun

Last updated 1 year ago.

tuyenlaptrinh, thank you. However, that doesn't address multiple categories. The regex is working. I can pull the categories and slug. The problem is that the slug is limited in length and I can't figure out why. I am not sure this is related to the regex as the problem happens on the {slug}/$slug parameter where no pattern is applied. I believe this because I can return the $cat and $slug and see the expected results for category and slug, until the slug exceeds 17 characters. Or, am I thinking of this totally wrong?

Last updated 1 year ago.

My skype

Can i support for you via skype.

I really don't know your problem.

Last updated 1 year ago.

Sorry, this problem has remained unsolved and was on the back burner until now. I updated the original post to include a test site to illustrate my problem:

You can test this at ({category1}/{category2}/.../{slug} -- this works -- this works

It is the last slug that can't be longer than 17 characters, so this: -- doesn't work.

To clarify the issue another time: This pattern allows me to have unlimited categories, the categories can be of any length, it is the final element, the slug, that can't be longer than 17 characters which is very limiting. I can't figure out why that is the only element being limited. Please help :)

Last updated 9 years ago.

I beat my head against the wall for a few more hours and started playing with the regex pattern. I couldn't get the idea out of my head that I was matching the final forwardslash of the categories, but also defining that forwardslash as the separator between {cat} and {slug} in the Route. This suspicion directed me towards positive lookaheads to remove the final forwardslash and slug from the result.

To be completely honest, I am not sure if this was the problem or not as I eventually resorted to easter egging regular expressions until I found something that works:

Route::pattern('cat2', '.+(?=\/.+)');

This pattern matches any character (.) one or more times (), followed by (?=) a forwardslash (/), any character (.) one or more times () without including it in the search (functionality of a positive lookahead ?=).

This can be verified at

If anybody would like to correct me, or expand on this it would be greatly appreciated.

Last updated 8 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.