Regular Expressions 101

Community Patterns

git url dissecting

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^((?<protocol>https?|ssh|git|ftps?):\/\/)?((?<user>[^\/@]+)@)?(?<host>[^\/:]+)[\/:](?<port>[^\/:]+)\/(?<path>.+\/)?(?<repo>.+?)(?<suffix>\.git[\/]?)?$
/

Description

the various parts of a git url are dissected and made available in the respective capture groups

Submitted by anonymous - 9 months ago