forked from nitin42/Python-Automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojec6.py
More file actions
36 lines (21 loc) · 689 Bytes
/
projec6.py
File metadata and controls
36 lines (21 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Regex search
# Traversing all the .txt files in a folder and searching for any line that matches regex
# Printing the result
import os
import re
# Opening .txt file
file_open = open(filename,'r')
try:
# User supplied regular expression
regex_in = raw_input("Enter the regular expression")
# Performing search initially
match = re.search(regex_in,filename)
# If Regular expression search successful
if match!=None:
# Make a complete search throughout the whole file
match_all = re.findall(regex_in,filename)
# Print the result
print "Result:" + str(match_all)
except IOError as e:
print ("File requested doesn't exist. Try again!")
file_open.close()