import reimport sys file = sys.stdintext = file.read()main_domain = "happy.com"subdomains = re.findall(r"^(?:(.+)\.)?%s$" % re.escape(main_domain), text, re.M)print(subdomains)
admin.happy.com nothappy.com happy.com
['admin', '']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!