Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98716 > unrolled thread

Is it useful for re.M in this example?

Started byfl <rxjwg98@gmail.com>
First post2015-11-12 13:34 -0800
Last post2015-11-12 22:32 -0500
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Is it useful for re.M in this example? fl <rxjwg98@gmail.com> - 2015-11-12 13:34 -0800
    Re: Is it useful for re.M in this example? John Gordon <gordon@panix.com> - 2015-11-12 22:00 +0000
    Re: Is it useful for re.M in this example? Terry Reedy <tjreedy@udel.edu> - 2015-11-12 22:32 -0500

#98716 — Is it useful for re.M in this example?

Fromfl <rxjwg98@gmail.com>
Date2015-11-12 13:34 -0800
SubjectIs it useful for re.M in this example?
Message-ID<fc8a4061-5156-41c8-bfd7-d9a8da462418@googlegroups.com>
Hi,

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?

Thanks,

[toc] | [next] | [standalone]


#98718

FromJohn Gordon <gordon@panix.com>
Date2015-11-12 22:00 +0000
Message-ID<n23260$kkj$2@reader1.panix.com>
In reply to#98716
In <fc8a4061-5156-41c8-bfd7-d9a8da462418@googlegroups.com> fl <rxjwg98@gmail.com> writes:

> 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:

That's because your sample string does not contain newline characters.
If it did, you would see the effect of re.M.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#98726

FromTerry Reedy <tjreedy@udel.edu>
Date2015-11-12 22:32 -0500
Message-ID<mailman.282.1447385576.16136.python-list@python.org>
In reply to#98716
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web