[Tutor] Re: Server stuff

Andrei project5 at redrival.net
Mon Aug 25 03:11:06 EDT 2003


Peter Brown wrote:
> 2. Is there an easy way to extract a sequence of at least 6 digits from a
> string. Can't rely on the digits to be in a word by themselves.

Use a regular expression:

   >>> import re
   >>> mystring = "asdf11111a2a33333333ef444444d"
   >>> myexpr = re.compile(r"(?:\d+){6}")
                   # at least six digits, no upper bounder
   >>> myexpr.findall(mystring)
   ['33333333', '444444']

>  It's mainly for text processing from a file that has to be checked if it
> exists and if it does I process the file and insert into postrgesQl

What's wrong with sleeping for this purpose?

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V 
ernq gur yvfg, fb gurer'f ab arrq gb PP.





More information about the Tutor mailing list