Home › Interview Questions › How would you extract the '.com' part from a strin…

How would you extract the '.com' part from a string such as 'youtube.com'?

🟢 Easy Conceptual Junior level
1Times asked
Oct 2026Last seen
Oct 2026First seen

💡 Model Answer

To extract the '.com' suffix from a string like 'youtube.com', you can use Python string methods or a regular expression. A simple approach is to split the string on the dot and take the last element: domain = url.split('.')[-1] which returns 'com'. If you need to ensure the string ends with '.com', you can use a regex: import re; match = re.search(r'\.com$', url); if match: suffix = match.group(0). This method runs in O(n) time where n is the length of the string.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500