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:
http://example.com/image/sky.jpg
http://example.com/about/image/forest.png
However it also matches:
http://example.com/patterns/site/image/image.html.php
That’s not intended and not wanted.
Exclude stuff
I never want it to match this:
http://example.com/panel/
http://example.com/patterns/
Never match what starts with panel/
and patterns/
.
That would be something like this:
image/.*\.(?:png|jpg)
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:
What about this …?
<?php $page = site()->find($uri); ?>
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.