# Permalink normalization regex problem

**URL:** https://meta.discourse.org/t/permalink-normalization-regex-problem/54373
**Category:** Development
**Created:** [December 17, 2016, 12:09am UTC](https://meta.discourse.org/t/permalink-normalization-regex-problem/54373 "2016-12-17T00:09:09Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 17, 2016, 12:09am UTC](https://meta.discourse.org/t/permalink-normalization-regex-problem/54373/1 "2016-12-17T00:09:09Z")

</div>

I’m trying to fix permalinks from URLs like this:

```
http://hostname/forum/category-slug-not-in-the-database/ID-slug-not-matching-title.html

```

My plan is to create permalinks like

```
 forum/ID --> topic id

```

and then a permalink normalization that strips the category slug and the topic slug like this:

```
/forum\/.*\/([0-9]+).*/forum\/\1

```

If I fix the URL by hand, it works, but I can’t get the `permalink normalization` to work. I’ve checked my regex at [http://regexr.com/](http://regexr.com/), but I’m still not getting it to work. Am I missing something obvious?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 17, 2016, 4:47pm UTC](https://meta.discourse.org/t/permalink-normalization-regex-problem/54373/2 "2016-12-17T16:47:37Z")

</div>

> [@pfaffman](#):
>
> /forum/._/([0-9]+)._/forum/\1

You don’t need to \ the `/` in the replacement string.

Edit:

```
/forum\/.\/([0-9]+?)./forum\/\1

```

Added `?` to fix topics with a title that starts with a number.
