Sometimes you need to pull just the domains out of a long block of text that mixes URLs with ordinary prose โ a server log, an email body, and so on.
Why a hand-rolled regex is tricky
A domain might appear without http(s)://, or come with a subdomain, port number, or path attached, making a single regex hard to get exactly right. Two-level country-code TLDs like .co.kr add another edge case, so a homemade pattern tends to miss things.
Common use cases
This comes up when tallying referrer domains from web server access logs, pulling out a list of sites mentioned in an email body, or checking suspicious domains bundled into a spam email all at once.
Deduplication and normalization
The same domain can appear in several forms depending on the presence of "www", capitalization, or protocol. Normalizing to lowercase and deduping after extraction is what makes the resulting count accurate.