0

Regex in python

i have learnt a lot about the regex and patterns in python but i can't do it i understood that if i want to make a pattern i have to do it like this pattern=r"blabla" i tried it on pycharm on pc put it didn't work the code was like that import re pat=r"abcd" i ="abcd" if re.match(pat,i): print "it works " else: print"smthg is wrong" the output was always "smthg is wrong" what did i miss?!!

14th Nov 2016, 1:47 PM
mohammed
mohammed - avatar
3 Respuestas
+ 1
Maybe you forgot to write parentheses for the print function. Try it: import re pat = r"abcd" i = "abcd" if re.match(pat,i): print ("it works ") else: print ("smthg is wrong")
16th Nov 2016, 5:33 PM
Vladimir Honcharenko
Vladimir Honcharenko - avatar
+ 1
try to use search method: if re.search(pat, i)
16th Nov 2016, 5:43 PM
Vladimir Honcharenko
Vladimir Honcharenko - avatar
0
don't think so cuz i tried it in many ways but always the same result
16th Nov 2016, 5:37 PM
mohammed
mohammed - avatar