Python (re)

GitHub Repository URL in PY

Match GitHub repository URLs and capture the owner and repo segments.

Try it in the PY tester →

Pattern

regexPY
https?:\/\/(?:www\.)?github\.com\/([A-Za-z0-9](?:[A-Za-z0-9\-]{0,38})?)\/([A-Za-z0-9._\-]{1,100})   (flags: g)

Python (re) code

pyPython
import re

pattern = re.compile(r"https?:\/\/(?:www\.)?github\.com\/([A-Za-z0-9](?:[A-Za-z0-9\-]{0,38})?)\/([A-Za-z0-9._\-]{1,100})")
input_text = "Source at https://github.com/vercel/next.js or https://www.github.com/torvalds/linux"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

https?:\/\/(?:www\.)?github\.com\/ matches the domain with optional www and either http/https. The first capture ([A-Za-z0-9](?:[A-Za-z0-9\-]{0,38})?) follows GitHub's username rules: 1–39 chars, alphanumeric + hyphens, no leading/trailing hyphen (simplified). The second capture matches the repo name with the broader allowed character set.

Examples

Input

Source at https://github.com/vercel/next.js or https://www.github.com/torvalds/linux

Matches

  • https://github.com/vercel/next.js
  • https://www.github.com/torvalds/linux

Input

Star: https://github.com/anthropics/claude-code

Matches

  • https://github.com/anthropics/claude-code

Input

no github links

No match

Same pattern, other engines

← Back to GitHub Repository URL overview (all engines)