Extract Domain Names from URLs Using RegEx
Beginner Mode
Start your terminal to use beginner mode.
Scenario
A file contains a list of URLs that need to be processed. You need to extract the domain names (including subdomains) from these URLs for analysis.
Task
Write a Python script at /home/interview/extract_domains.py that reads URLs from /home/interview/urls.txt, extracts the domain names using regex, and saves them to /home/interview/domains.txt (one domain per line).
Example
Input URL examples:
https://www.example.com/path/to/page
http://api.service.org:8080/endpoint
ftp://files.company.co.uk/downloads
Expected output format in /home/interview/domains.txt:
www.example.com
api.service.org
files.company.co.uk
Terminal requires a larger screen
Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.
Linux Terminal Environment
Write and execute your solution in the terminal below.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
OpenAI