[Tutor] Re Module
Asad
asad.hasan2004 at gmail.com
Thu Dec 27 10:10:12 EST 2018
Hi All ,
I trying find a solution for my script , I have two files :
file1 - I need a search a error say x if the error matches
Look for the same error x in other file 2
Here is the code :
I have 10 different patterns therefore I used list comprehension and
compiling the pattern so I loop over and find the exact pattern matching
re_comp1 = [re.compile(pattern) for pattern in str1]
for pat in re_comp1:
if pat.search(st,re.IGNORECASE):
x = pat.pattern
print x ===> here it gives the expected output it correct
match
print type(x)
<type 'unicode'>
if re.search('x', line, re.IGNORECASE) is not None: ===> Gives a wrong
match
print line
Instead if I use :
if re.search(x, line, re.IGNORECASE) is not None: then no match occurs
print line
Please advice where I going wrong or what can be done to make it better .
Thanks,
--
Asad Hasan
+91 9582111698
More information about the Tutor
mailing list