#!/usr/bin/python3 
# regexsearh.py based on the "regex search" assignment in chapter 8 of 
# Auotmate the Boring Stuff with Python.
# The script finds all .txt files in a directory it was run in and matches any context in those files 
# based on a user provided regex pass via a cli argument.
# 
# Usage: regexsearch.py <regular expression>  
#

import re, os, sys #use re for regex, os for listdir, and sys for argv  

files = os.listdir('.') #Get all files in the current directory 

for i in files: # loop through each file
	if i.endswith('.txt'):  # does the file end with .txt ? 
		txtfile = open(i) # open the file ending with .txt 
		txtfile = txtfile.read() # read the file 
		regex = re.compile(sys.argv[1]) #pass the user's argument as regex 
		find = regex.findall(txtfile) # find all occurances of the user's regex in the .txt file 
		if find: #if find equals true, meaning a match has been found. 
			print('Match in file: ' + i + '\n' + str(find))  # print the file and the match 

0e7621dd674b7ed3da1df0a62bce0130805313b3
<mask token>

<mask token>
for i in files:
    if i.endswith('.txt'):
        txtfile = open(i)
        txtfile = txtfile.read()
        regex = re.compile(sys.argv[1])
        find = regex.findall(txtfile)
        if find:
            print('Match in file: ' + i + '\n' + str(find))

<mask token>
files = os.listdir('.')
for i in files:
    if i.endswith('.txt'):
        txtfile = open(i)
        txtfile = txtfile.read()
        regex = re.compile(sys.argv[1])
        find = regex.findall(txtfile)
        if find:
            print('Match in file: ' + i + '\n' + str(find))

import re, os, sys
files = os.listdir('.')
for i in files:
    if i.endswith('.txt'):
        txtfile = open(i)
        txtfile = txtfile.read()
        regex = re.compile(sys.argv[1])
        find = regex.findall(txtfile)
        if find:
            print('Match in file: ' + i + '\n' + str(find))

#!/usr/bin/python3 
# regexsearh.py based on the "regex search" assignment in chapter 8 of 
# Auotmate the Boring Stuff with Python.
# The script finds all .txt files in a directory it was run in and matches any context in those files 
# based on a user provided regex pass via a cli argument.
# 
# Usage: regexsearch.py <regular expression>  
#

import re, os, sys #use re for regex, os for listdir, and sys for argv  

files = os.listdir('.') #Get all files in the current directory 

for i in files: # loop through each file
	if i.endswith('.txt'):  # does the file end with .txt ? 
		txtfile = open(i) # open the file ending with .txt 
		txtfile = txtfile.read() # read the file 
		regex = re.compile(sys.argv[1]) #pass the user's argument as regex 
		find = regex.findall(txtfile) # find all occurances of the user's regex in the .txt file 
		if find: #if find equals true, meaning a match has been found. 
			print('Match in file: ' + i + '\n' + str(find))  # print the file and the match 
