Skip to content

Instantly share code, notes, and snippets.

@claudijd
Last active October 1, 2019 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudijd/3c89c22314ca4c7ec556a4c74d469aff to your computer and use it in GitHub Desktop.
Save claudijd/3c89c22314ca4c7ec556a4c74d469aff to your computer and use it in GitHub Desktop.
import re
# Current
>>> re.search(r"((ssh|https)://)?(git@)?github.com[:/](?P<repo_name>[A-Za-z0-9\/\-_]+)(.git)?", "bananas://github.com:/")
'/'
# Proposed
>>> re.search(r"^((https|ssh)://)?(git@)?github.com/(?P<repo_name>[A-Za-z0-9\/\-_]+)(.git)?$", "https://github.com/org/foo").group("repo_name")
'org/foo'
>>> re.search(r"^((https|ssh)://)?(git@)?github.com/(?P<repo_name>[A-Za-z0-9\/\-_]+)(.git)?$", "https://github.com/org/foo.git").group("repo_name")
'org/foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment