# Route regex, prevent some words

**URL:** <https://forum.getkirby.com/t/route-regex-prevent-some-words/3308>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 12, 2016, 7:10am UTC](https://forum.getkirby.com/t/route-regex-prevent-some-words/3308 "2016-02-12T07:10:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [February 12, 2016, 7:10am UTC](https://forum.getkirby.com/t/route-regex-prevent-some-words/3308/1 "2016-02-12T07:10:58Z")

</div>

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

**I’ve come this far:**

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

```

**It matches like:**

```http
http://example.com/image/sky.jpg
http://example.com/about/image/forest.png

```

**However it also matches:**

```http
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
http://example.com/panel/
http://example.com/patterns/

```

Never match what starts with `panel/` and `patterns/`.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [February 12, 2016, 11:42am UTC](https://forum.getkirby.com/t/route-regex-prevent-some-words/3308/2 "2016-02-12T11:42:37Z")

</div>

That would be something like this:

```auto
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:

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

```

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [February 12, 2016, 2:12pm UTC](https://forum.getkirby.com/t/route-regex-prevent-some-words/3308/3 "2016-02-12T14:12:01Z")

</div>

The alternative solution is fine, thanks!

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

> [@Switching language without having access to the page object](https://forum.getkirby.com/t/switching-language-without-having-access-to-the-page-object/3309/2):
>
> 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.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [February 12, 2016, 8:43pm UTC](https://forum.getkirby.com/t/route-regex-prevent-some-words/3308/4 "2016-02-12T20:43:41Z")

</div>

> [@jenstornell](#):
>
> I often go back to look at questions me and others have asked before.

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

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:00pm UTC](https://forum.getkirby.com/t/route-regex-prevent-some-words/3308/5 "2025-02-06T17:00:13Z")

</div>


