Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Search for a pattern in a file with python
# Open file
f = open('test.txt', 'r')
# Feed the file text into findall(); it returns a list of all the found strings
strings = re.findall(r'some pattern', f.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment