[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Need help with a regular expression

Sharun

12/19/2007 12:08:00 PM

Python newbie here. I am not clear about how the matching is taking
place when I do the following

>str5 = 'aaa bbb\r\n ccc ddd\r\n eee fff'
>re5=re.compile('aaa.*(ddd|fff)',re.S);
>re5.search(str5).group(0)
'aaa bbb\r\n ccc ddd\r\n eee fff'

>re5.search(str5).group(1)
'fff'

I am trying to find the substring starting with 'aaa', and ending with
ddd OR fff. If ddd is found shouldnt the search stop? Shouldn't
re5.search(str5).group(0) return 'aaa bbb\r\n ccc ddd' ?

Thanks
4 Answers

marek.rocki

12/19/2007 12:19:00 PM

0

On 19 Gru, 13:08, Sharun <sharun...@gmail.com> wrote:
> I am trying to find the substring starting with 'aaa', and ending with
> ddd OR fff. If ddd is found shouldnt the search stop? Shouldn't
> re5.search(str5).group(0) return 'aaa bbb\r\n ccc ddd' ?

The documentation for the re module (http://docs.python.o...
syntax.html), tells you that the "*", "+", and "?" qualifiers are all
greedy; they match as much text as possible. What you are looking for
are the qualifiers "*?", "+?", "??". Your regex pattern might look
like this: "aaa.*?(ddd|fff)".

Regards,
Marek

Paddy

12/19/2007 12:46:00 PM

0

On Dec 19, 12:08 pm, Sharun <sharun...@gmail.com> wrote:
> Python newbie here. I am not clear about how the matching is taking
> place when I do the following
>
> >str5 = 'aaa bbb\r\n ccc ddd\r\n eee fff'
> >re5=re.compile('aaa.*(ddd|fff)',re.S);
> >re5.search(str5).group(0)
>
> 'aaa bbb\r\n ccc ddd\r\n eee fff'
>
> >re5.search(str5).group(1)
>
> 'fff'
>
> I am trying to find the substring starting with 'aaa', and ending with
> ddd OR fff. If ddd is found shouldnt the search stop? Shouldn't
> re5.search(str5).group(0) return 'aaa bbb\r\n ccc ddd' ?
>
> Thanks

Have an RE problem in Python?

Get Kodos! (http://kodos.source...)

- Paddy.

Sharun

12/19/2007 12:59:00 PM

0

Thanks Marek!

volkfolk

3/18/2011 12:37:00 PM

0

On Mar 18, 8:04 am, James Pablos <james.pab...@gmail.com> wrote:
> On Mar 17, 9:37 pm, Ray <rayb...@hotmail.com> wrote:
>
> > I still don't understand why you care at all, let alone seem so deeply
> > bothered by it.
>
> Because it compromises artistic integrity; the boys (and girl) in the
> band should be the ones creating the setlist. They are the ones who
> make the music, so why shouldn't they make the setlists as well?

You really have NO idea what the fuck you're talking about. You keep
on saying that it somehow compromises the artistic integrity of what
they are doing. How? You don't play music, you're not in a band, you
have no idea of what is involved with putting together a performing
band. As a musician I can tell you that who picks the order of the
songs doesn't matter. The fact that you have such a stick up your ass
about this just proves that you have no idea WTF you're talking about.

> I mean, it sorta worked for the Grateful Dead, didn't it?

Sometimes it and sometimes it didn't. If they were playing shitty it
didn't make any difference how "great" the setlist was

Scot