Regular Expressions 101

Community Patterns

Domain and locale extraction regex

0

Regular Expression
ECMAScript (JavaScript)

/
^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/?\n]+)?(\/)?([a-z]{2}-[a-z]{2})
/
gmi

Description

Regex that captures both domain and locale for a given url. Eg: https://sumup.com/en-en/welcome

matches https://sumup.com/en-en

Submitted by anonymous - 4 years ago