I have the following regex: `(?:\/us)?\/[a-z]{2}[_-][a-z]{2}(?:\/?$|(?=\/))|\/[a-z]{2}(?:\/?$|(?=\/))^([a-z]{2}\/retail)`

As you can see, it's not particularly easy on the eyes. You can see it in action here: <https://regex101.com/r/4AZwuP/1> (enable substitutions to see the desired result - the removal of matches)

Here's a few entries it's supposed to match:

```
/us/en_us/retail/en (matches /us/ and /us/en_us/)
/us/en_us/retail (matches /us/ and /en_us/)
/gb/en_gb/retail/en-uk (matches /en_gb and /en-uk)

```

Note that, these are just prefixes and the full url might look something like:

`/de/de_de/retail/de_de/products/catalog`

The goal is to run the regex and delete matches so that this lines becomes:

`de/retail/products/catalog`

**The above Regex accomplishes this with one exception: in the first example, I need it to match not only `/us/en_us` but also `/en` (or `/de` or `/mx` - in other words, there's an additional country code there; it unfortunately does not.**

What I do know for a fact is that if those two characters are present, it'll be one of these two:

* `.../retail/en`
* `.../retail/en/something/or/other`

In either case it's always two characters either alone or followed by a forward slash.

#### How can I modify the original regex to deal with this annoying edge case?

Bonus: how does the original work?