How to make a regex expression?

A url from $_SERVER["REQUEST_URI"]:

1. Home sitename.com/ru, sitename.com/en, sitename.com/de and so on.
2. Inner pages sitename.com/ru/account, sitename.com/ru/account/edit and so on

You need to cut the name of the language given the fact that you can add new locale 3 letter or 4 letter.

Thought that solved the problem pattern ~\/(.*)\/|\/\w{1,4}~, but it was not there.

Help make Virginia.

The result should be:
sitename.com/ru -> /
sitename.com/de -> /
sitename.com/ru/account -> account
sitename.com/ru/account/edit -> account/edit
June 10th 19 at 15:12
3 answers
June 10th 19 at 15:14
June 10th 19 at 15:16
~/([^/]+)~
June 10th 19 at 15:18
([\w\.]+)(\/)(\w+)(/.*)

Find more questions by tags Regular expressionsPHP