Skip to content

Instantly share code, notes, and snippets.

@robot00f
Created January 15, 2023 03:15
Show Gist options
  • Save robot00f/e0180c61e4d65864e1f62465571e474c to your computer and use it in GitHub Desktop.
Save robot00f/e0180c61e4d65864e1f62465571e474c to your computer and use it in GitHub Desktop.
Example: extract email and password from a text file.
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment