how to determine an 'open' string?

holger krekel pyth at devel.trillke.net
Thu May 16 17:24:56 EDT 2002


John La Rooy wrote:
> On Thu, 16 May 2002 18:59:17 +0200
> holger krekel <pyth at devel.trillke.net> wrote:
> 
> 
> > 
> > i think that's it. very nice! 
> > 
> > i might try to shorten it a bit, though :-)
> > 
> > thanks,
> > 
> >     holger
> > 
> > 
> 
> is this short enough for you?
> 
> import re
> 
> def quoteopen(s):
>     quot=re.compile("(?P<quot>\"\"\"|'''|\"|').*?(?P=quot)")
>     s=quot.sub("",s)
>     return "'" in s or '"' in s

my other version also returns the 'open quote' but
yours is shorter. you won :-)

regexes often offer more than one might think...

thanks,

    holger





More information about the Python-list mailing list