regex.py 403 B

1234567891011121314151617
  1. """Regex utils"""
  2. from __future__ import annotations
  3. import re
  4. RE_REPOSITORY = re.compile(
  5. r"(?:(?:.*github.com.)|^)([A-Za-z0-9-]+\/[\w.-]+?)(?:(?:\.git)?|(?:[^\w.-].*)?)$"
  6. )
  7. def extract_repository_from_url(url: str) -> str | None:
  8. """Extract the owner/repo part form a URL."""
  9. match = re.match(RE_REPOSITORY, url)
  10. if not match:
  11. return None
  12. return match.group(1).lower()