I have a following link structure:
/type1
/type2
/type3
those links correspond to the default language of the site. Unfortunately the client didn't want to add the default language in front of the URL for consistency, therefore only other languages will have URLs like:
/en
/en/type1
/de/type2
/de
/fr/type3
/fr
There are a lot of other variables but only this part is dynamic. My Regex starts as following:
(en|de|fr)?\/?(type1|type2|type3)?\/?
which basically means capture the language if exists, and then capture the page if exists. But it performs a lot more matches than required and also would capture empty string etc.
I'm trying to figure out how to capture all these options:
/en
/en/type1
/type1
in one expression, of course if possible. How can I make one of the two groups to be required, so basically the URL has either both or one of them but never none? I looked at backreferences in conjunction with look-aheads but I think I'm missing some crucial information here...
I would like to preserve the groups so that group1 = language
and group2 = page