What is 're.M'?

rxjwg98 at gmail.com rxjwg98 at gmail.com
Mon Jul 7 10:08:53 EDT 2014


Hi,

I learn this short Python code from:

http://www.tutorialspoint.com/python/python_reg_expressions.htm

but I still do not decipher the meaning in its line, even after read its command
explanation.

It says that:
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). 

More specific, what does 're.M' means? 

I have tried several other modification to the searchObj line, without clue yet.


Could you explain re.M and the following two searchObj mechanisms?

Thanks,



import re

line = "Cats are smarter than dogs";


searchObj = re.search( r'(.*) (.*?) .*', line, re.M|re.I)
# searchObj = re.search( r'(.*) (.*?) .*', line, re.M|re.I)

if searchObj:
   print "searchObj.group() : ", searchObj.group()
   print "searchObj.group(1) : ", searchObj.group(1)
   print "searchObj.group(2) : ", searchObj.group(2)
else:
   print "Nothing found!!"



More information about the Python-list mailing list