On 11/12/2015 4:34 PM, fl wrote:
I follow a web site on learning Python re. I have read the function description of re.m, as below.
re.M Makes $ match the end of a line (not just the end of the string) and makes ^ match the start of any line (not just the start of the string). But I don't see the reason to put re.M in the example project: #!/usr/bin/python import re line = "Cats are smarter than dogs"; matchObj = re.match( r'dogs', line, re.M|re.I) if matchObj: print "match --> matchObj.group() : ", matchObj.group() else: print "No match!!" The tutorial (http://www.tutorialspoint.com/python/python_reg_expressions.htm) is for a beginner as I. Is there something I don't see in the example?
No. The use of re.M in the examples is doubly irrelevant since there is no \n in line and no $ in the pattern. Re.I is also not relevant since there is no case-insensitive matchin. It appears that the author routinely uses flags=re.M|re.I. For a tutorial, I would have omitted either omitted them or explained them as routine boilerplate.
-- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list