Route regex, prevent some words

I’m really bad at regex and needs something that probably are simple for an regex pro.

I’ve come this far:

'pattern' => array('(.*?/image/.+)', '(^image/.+)'),

It matches like:

However it also matches:

That’s not intended and not wanted.

Exclude stuff

I never want it to match this:

Never match what starts with panel/ and patterns/.

That would be something like this:


This will also match files in /pattern and /panel though. You could probably use a negative lookbehind assertion for this, but the performance of these is not that great and it makes it all complicated.

An alternative would be to check if the URI starts with either of these strings before registering the route:

if(!str::startsWith(url::path(), 'panel') && !str::startsWith(url::path(), 'patterns')) {
  // Register route

The alternative solution is fine, thanks!

However I can’t do it like I wanted anyway because of this issue:

But this answer will probably come in handy in the future. I often go back to look at questions me and others have asked before.

Me too! That’s why there is a Kirby forum. :slight_smile: