Write a regular expression, usable with Python's re.search, which captures in its capture groups the parts of a rudamentary URL as defined below: Examples of URLs: http://bing.com https://google.com https://yahoo.com https://www.ycombinator.com/ The pattern should capture: The scheme (the "https://" part) The domain (the part after the scheme and before the top level domain (TLD), e.g. "bing" or "www.ycombinator") The top
Write a regular expression, usable with Python's re.search, which captures in its capture groups the parts of a rudamentary URL as defined below:
Examples of URLs:
http://bing.com
https://google.com
https://yahoo.com
https://www.ycombinator.com/
The pattern should capture:
The scheme (the "https://" part) The domain (the part after the scheme and before the top level domain (TLD), e.g. "bing" or "www.ycombinator") The top level domain (aka. TLD) (the last part, eg. "edu", "com", "gov")
You do not need to handle URLs with paths (such as http://google.com/foo/bar), unless the path is just / as above, nor do you need to handle URLs with query strings (such as https://example.com?foo=bar).
For the last example:
>>> re.search(pattern, 'https://www.ycombinator.com/').groups()
('https://', 'www.ycombinator', 'com')
Assign your pattern to a variable named pattern.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images