I was wondering how to extract all the valid subdomains and domains from any file content. Many sites can extract domains from any text online. but I was wondering, how can I do this on the terminal using a linux machine.
Using grep I can do this using this regex: (?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]
Example:
echo "extract example.com and a.example.cloud. from all content " | grep -oP "(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]"
Any other ways of doing this?