Skip to content

Instantly share code, notes, and snippets.

@sbatururimi
Created October 31, 2018 08:51
Show Gist options
  • Save sbatururimi/1ab1b3ee119f6f24d54f3a253c632797 to your computer and use it in GitHub Desktop.
Save sbatururimi/1ab1b3ee119f6f24d54f3a253c632797 to your computer and use it in GitHub Desktop.
Parsing urls to obtain for example the host
regex = r"^[a-z][a-z0-9+\-.]*:\/\/([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-z0-9\-._~%!$&'()*+,;=:]+\])"
\A
[a-z][a-z0-9+\-.]*:// # Scheme
([a-z0-9\-._~%!$&'()*+,;=]+@)? # User
([a-z0-9\-._~%]+ # Named or IPv4 host
|\[[a-z0-9\-._~%!$&'()*+,;=:]+\]) # IPv6+ host
Source
https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s10.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment