I am trying to count the number of times a user entered regular expression shows up in any file, but the list created by findall keeps returning as empty.... help is appreciated!
reg = input('Enter a regular expression ')
fname = input('Enter file name ')
try:
fhand = open(fname, 'r')
except:
print('Cannot open file')
quit()
for line in fhand:
line = line.strip()
matches = re.findall('(reg)', line)
print(matches, len(matches))
print(fname, 'had', len(matches), 'that matched', reg)