If you're trying to match /en/
specifically, you don't need a regular expression at all. Just use your language's equivalent of contains
to test for that substring.
If you're trying to match any two-letter part of the URL between two slashes, you need an expression like this:
/../
If you want to capture the two-letter code, enclose the periods in parentheses:
/(..)/
Depending on your language, you may need to escape the slashes:
\/..\/
\/(..)\/
And if you want to make sure you match letters instead of any character (including numbers and symbols), you might want to use an expression like this instead:
/[a-z]{2}/
Which will be recognized by most regex variations.
Again, you can escape the slashes and add a capturing group this way:
\/([a-z]{2})\/
And if you don't need to escape them:
/([a-z]{2})/
This expression will match any string in the form /xy/
where x
and y
are letters. So it will match /en/
, /fr/
, /de/
, etc.
In JavaScript, you'll need the escaped version: \/([a-z]{2})\/
.