RegEx Redirects for Legacy URLs 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 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.
Here's the regex I think you'll need:


\/teachings\/tag\/\d+\/(\w+)\/? → \/teachings\/topics\/$1
\/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!