Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Kent Johnson
Steve Nelson wrote: > Incidentally continuing my reading of the HOWTO I have sat and puzzled > for about 30 mins on the difference the MULTILINE flag makes. I can't > quite see the difference. I *think* it is as follows: > > Under normal circumstances, ^ matches the start of a line, only. On a >

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > But for this particular application you might as well use > line.startswith('b') instead of a regex. Ah yes, that makes sense. Incidentally continuing my reading of the HOWTO I have sat and puzzled for about 30 mins on the difference the MULT

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Kent Johnson
Steve Nelson wrote: > On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > > > m = re.match(...) > dir(m) > >> It will tell you what attributes the match object has. >> > > Useful - thank you. > > I am now confuse on this: > > I have a file full of lines beginning with

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Luke Paireepinart
> I have a file full of lines beginning with the letter "b". I want a > RE that will return the whole line if it begins with b. > > I find if I do eg: > > m = re.search("^b", "b spam spam spam") m.group() > 'b' > > How do I get it to return the whole line if it begins w

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > >>> m = re.match(...) > >>> dir(m) > > It will tell you what attributes the match object has. Useful - thank you. I am now confuse on this: I have a file full of lines beginning with the letter "b". I want a RE that will return the whole line

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread John Fouhy
On 14/07/06, Steve Nelson <[EMAIL PROTECTED]> wrote: > How does one query a match object in this way? I am learning by > fiddling interactively. If you're fiddling interactively, try the dir() command -- ie: >>> m = re.match(...) >>> dir(m) It will tell you what attributes the match object has

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Kent Johnson
Steve Nelson wrote: > On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > > >> It doesn't have to match the _whole_ string. >> > > Ah right - yes, so it doesn't say that it has to end with a b - as per > your comment about ending with $. > The matched portion must end with b, but it does

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > It doesn't have to match the _whole_ string. Ah right - yes, so it doesn't say that it has to end with a b - as per your comment about ending with $. > If you look at the match object returned, you should se that the match > starts at position

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread John Fouhy
On 14/07/06, Steve Nelson <[EMAIL PROTECTED]> wrote: > What I don't understand is how in the end the RE *does* actually match > - which may indicate a serious misunderstanding on my part. > > >>> re.match("a[bcd]*b", "abcbd") > <_sre.SRE_Match object at 0x186b7b10> > > I don't see how abcbd matches

[Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
Hello, I am reading the "Regular Expression HOWTO" at http://www.amk.ca/python/howto/regex/ I am at the bit where "greediness" is discussed with respect to metacharacters enabling repetition of sections of a RE. I understand the concept. The author gives a step by step example of how the matchi