<p>Here's the regex I think you'll need:</p>

<ol>
<li><code>\/teachings\/tag\/\d+\/(\w+)\/?</code> → <code>\/teachings\/topics\/$1</code></li>
<li><code>\/teachings\/series\/\d+\/(\w+)\/?</code> → <code>\/teachings\/series\/$1</code></li>
</ol>

<p>A couple explanations:</p>

<ul>
<li><code>\/</code> is an escaped <code>/</code> character</li>
<li><code>\d+</code> means one or more digit (0-9)</li>
<li><code>\w+</code> means one or more alphanumeric/underscore character (A-Z, a-z, 0-9, _)</li>
<li>surrounding something in parentheses makes it a capturing group, which can then be referenced when you're doing the "replace"</li>
</ul>

<p>So in our regex we're matching the current url structures, capturing the slug, and then using that in the new url structures. Hopefully that helps!</p>

CC BY-SA 4.0
2019-08-30T21:25:08.463Z
This worked perfectly! With the way `retour` handles the `Destination URL` filed the escaped sequences generated `//teachings//topics...`. I shortened the `Destination URL` portions to `/teachings/topics/$1`, etc. and it worked perfectly.
Jonathan Simcoe
CC BY-SA 4.0
2019-08-30T18:46:58.373Z
2019-08-30T18:46:58.373Z
Jalen Davenport
<p>My legacy URLs have this structure:</p>

<p><code>/teachings/tag/13721/omnipotent/</code> or
<code>/teachings/series/17764/fearless/</code></p>

<p>For both the <code>tag</code> and the <code>series</code> they are always followed by a string of digits and then slug I want to capture and redirect to the new formats:</p>

<p><code>/teachings/topics/omnipotent</code> and
<code>/teachings/series/fearless</code></p>

<p>I've tried various ways using <a href="https://regexr.com/" rel="nofollow noreferrer">https://regexr.com/</a> to capture the slug and target each legacy URL but I can't seem to figure it out. I've seen the basic instructions <a href="https://craftcms.stackexchange.com/questions/23575/how-do-i-redirect-from-a-legacy-category-url-to-a-new-catgory-url-using-retour">here</a> but I can't seem to find a way to target the unique legacy formats of these strings.</p>

<p>Any help you can provide would be greatly appreciated.</p>

CC BY-SA 4.0
2022-06-03T13:33:53.880Z
My legacy URLs have this structure:
/news?id=beechbrook-capital-provide-follow-on-capital-to-the-bhsl-group-to-facilitate-growth-&s=0.446550675146
and i want:
/news/beechbrook-capital-provide-follow-on-capital-to-the-bhsl-group-to-facilitate-growth
i want to remove -&s=0.444455..
please help
Mustufa Limdiwala
<regex><plugin-retour>
RegEx Redirects for Legacy URLs
# RegEx Redirects for Legacy URLs

(Asked by: username_0 on 2019-08-30)

My legacy URLs have this structure:

`/teachings/tag/13721/omnipotent/` or
`/teachings/series/17764/fearless/`

For both the `tag` and the `series` they are always followed by a string of digits and then slug I want to capture and redirect to the new formats:

`/teachings/topics/omnipotent` and
`/teachings/series/fearless`

I've tried various ways using <https://regexr.com/> to capture the slug and target each legacy URL but I can't seem to figure it out. I've seen the basic instructions [here](https://craftcms.stackexchange.com/questions/23575/how-do-i-redirect-from-a-legacy-category-url-to-a-new-catgory-url-using-retour) but I can't seem to find a way to target the unique legacy formats of these strings.

Any help you can provide would be greatly appreciated.

**Tags:** regex, plugin-retour

> **Comments:**
> **username_1**: My legacy URLs have this structure: /news?id=beechbrook-capital-provide-follow-on-capital-to-the-bhsl-group-to-facilitate-growth-&s=0.446550675146 and i want: /news/beechbrook-capital-provide-follow-on-capital-to-the-bhsl-group-to-facilitate-growth i want to remove -&s=0.444455.. please help  

---

## 1 answers

### Answer by username_2 on 2019-08-30. Score: 3

Here's the regex I think you'll need:

1. `\/teachings\/tag\/\d+\/(\w+)\/?` → `\/teachings\/topics\/$1`
2. `\/teachings\/series\/\d+\/(\w+)\/?` → `\/teachings\/series\/$1`

A couple explanations:

* `\/` is an escaped `/` character
* `\d+` means one or more digit (0-9)
* `\w+` means one or more alphanumeric/underscore character (A-Z, a-z, 0-9, \_)
* surrounding something in parentheses makes it a capturing group, which can then be referenced when you're doing the "replace"

So in our regex we're matching the current url structures, capturing the slug, and then using that in the new url structures. Hopefully that helps!

> **Comments:**
> **username_0**: This worked perfectly! With the way `retour` handles the `Destination URL` filed the escaped sequences generated `//teachings//topics...`. I shortened the `Destination URL` portions to `/teachings/topics/$1`, etc. and it worked perfectly.  

---

