import re # Open the text file with open("textfile.txt", "r") as file: # Read the contents of the file data = file.read() # Use regular expressions to find the email and password in the text email_regex = r'[\w\.-]+@[\w\.-]+' password_regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b|\b\S{8,}\b' emails = re.findall(email_regex, data) passwords = re.findall(password_regex, data) # Open the output file in write mode with open("output.txt", "w") as output: # Write the emails and passwords to the output file for i in range(len(emails)): output.write(emails[i] + ":" + passwords[i] + "\n")