Advertisement

Pattern library / URLs & Marketing

GitHub URL Regex

https://github.com/adityaeza7-beep/regexlab — but also http://, www., deep links (/tree/main/src, ?tab=repos) and the SSH form your git config actually uses. This pattern matches the web forms, requires owner/repo, and the notes show the capture groups that split them apart.

The pattern
^https?://(www\.)?github\.com/[A-Za-z0-9-]+/[A-Za-z0-9_.-]+([/?].*)?$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
https://github.com/adityaeza7-beep/regexlabMatchcanonical repository URLTry →
https://github.com/aloisdg/awesome-regex/tree/main/listsMatchdeep link with /tree/Try →
https://github.com/user/repo?tab=reposMatchquery-only tail after the repoTry →
github.com/user/repoNo matchno scheme — optional variant in notesTry →
https://github.com/octocatNo matchowner without a repo segmentTry →
git@github.com:user/repo.gitNo matchSSH form — different shape entirelyTry →

Where to use it

JavaScript (owner + repo)

const m = url.match(/^https?:\/\/(www\.)?github\.com\/([^/]+)\/([^/?#]+)/);
// m[2] = owner, m[3] = repo

Python

import re
m = re.match(r'^https?://(?:www\.)?github\.com/([^/]+)/([^/?#]+)', url)
owner, repo = m.groups() if m else (None, None)

Bash (grep repo links)

grep -Eo '^https?://(www\.)?github\.com/[A-Za-z0-9-]+/[A-Za-z0-9_.-]+' urls.txt | head

Common mistakes

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

FAQ

How do I extract the owner and repo name?

Use the capture variant from the notes: ^https?://(www\.)?github\.com/([^/]+)/([^/?#]+). Groups 2 and 3 are owner and repo — group 3 stops before /tree/, /issues or ?query.

Why does git@github.com:user/repo.git not match?

It is the SSH remote form, not a URL: no slashes after the host, colon instead. Test it with ^git@github\.com:([^/]+)/([^/]+)(\.git)?$ instead.

How do I match any github.com link, including profiles?

Drop the required repo part: ^https?://(www\.)?github\.com/[A-Za-z0-9-]+(/[A-Za-z0-9_.-]+)*(/.*)?$ — accept that it also matches 404-prone paths, then filter captures in code.

URL Regex — Match http/https Links (Practical) · YouTube URL Regex - watch, youtu.be & Shorts (Extract Video ID) · Extract Domain from URL — Regex Capture Group

For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.