Isn't re.findall supposed to find all?
June Kim
junaftnoon at nospamplzyahoo.com
Fri Nov 10 20:45:42 EST 2000
"June Kim" <junaftnoon at nospamplzyahoo.com> wrote in message
news:8ui0i5$nfc$1 at news.nuri.net...
>
> Well, I forgot the old rule "Longest match possible."
> It worked perfectly with this:
> >>> z
> '[abcdefrdofhd]kdeioslkdfj[sdkfj]'
> >>> p=re.compile('\[[^\[]*\]')
> >>> re.findall(p,z)
> ['[abcdefrdofhd]', '[sdkfj]']
>
> But another problem emerged. What if the brackets were
> longer than one character? for example:
> z='this is yet another start of a sting end but never start an end'
>
> opening bracket : "start"
> closing bracket : "end"
>
> What I want to get is,
>
> re.findall(p,z) == ['[start of a string end]','[start an end]']
>
> How should I render the regular expression?
>
> Thanks in advance
>
> ---------
> June
>
I found out one way to do it! (bravo)
p=re.compile('start.*?end')
re.findall(p,z)
But my question still remains; I want to find a substring
that starts with a specific string, say XYZ and ends with
another specific string, say QPR, but hasn't got a string,
LMN in between the opener and the closer.
e.g. XYZ....(any length of letters but no LMN here).....QPR
Could any one enlighten me kindly?
=====
June
More information about the Python-list
mailing list