1.I have a file named rexp.txt
with the following content:
adf fdsf hh h fg h 1995-11-23
dasvsbh 2000-04-12 gnym,mnbv 2001-02-17
dascvfbsn
bjhmndgfh
xgfdjnfhm244-44-2255 fgfdsg gfjhkh
fsgfdh 455-44-6577 dkjgjfkld
sgf
dgfdhj
sdg 192.6.8.02 fdhdlk dfnfghr
fisdhfih dfhghihg 154.56.2.6 fdhusdgv
aff fjhgdf
fdfdnfjgkpg
fdf hgj fdnbk gjdhgj
dfdfg raeh95@gmail.com efhidhg fdfuga reg@gmail.com
ergudfi rey@gmail.com iugftudfh dgufidjfdg
teeeee@gmail.comugfuhlfhs fgufif p
2.I want to extract the ssn number, date, e-mail line by line. I'm expecting code that loops through every line and returns the expected strings.
3.Correct the coding in Python:
import re
def cfor_date(str):
t=re.search(r'(\d{4}-\d{2}-\d{2})',str)
return t
def cfor_ssn(str):
f=re.search(r'(\d{3}-\d{2}-\d{4})',str)
return f
def cfor_gm(str):
g=re.search(r'([\w\.-]+@gmail[\w{3}\.-]+)',str)
return g
f = open("rexp.txt","r").read()
lines = f.splitlines()
for line in iter(lines):
x=line.split(" ")
print x
if (cfor_date(x)) != None: # i feel problem here
r=cfor_ssn(x)
print r