Host names from URLs
A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.
The task
Find the first http or https URL on the line and capture its host name in group 1: everything after :// up to a slash, colon, question mark, hash or whitespace.
What this exercise teaches
https?://([^/:?#\s]+) stops the host at the first character that starts a port, path, query or fragment.
A hint if you get stuck
Use a negated class listing every character that ends the host.
This exercise is part of Pro
Pro unlocks all 52 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.