Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
ECMAScript (JavaScript)

/
(https?:\/\/)?github\.com\/(?<author>[\w-]+)\/(?<repo>[\w-]+)\/?(tree\/)?(?<branch>[\w-]+)?
/
gm

Description

A regular expression for extracting the author, repository name, and optional branch from a GitHub repository or tree URL. Handles both HTTP(S) and direct GitHub links.

Submitted by Xain - 2 months ago