Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!transit4.readnews.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: re.sub(): replace longest match instead of leftmost match? Date: Fri, 16 Dec 2011 21:07:30 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 24 Message-ID: References: NNTP-Posting-Host: panix2.panix.com X-Trace: reader1.panix.com 1324069650 24307 166.84.1.2 (16 Dec 2011 21:07:30 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 16 Dec 2011 21:07:30 +0000 (UTC) User-Agent: nn/6.7.3 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17386 In Roy Smith writes: > Having done quite a bit of IPv6 work, my opinion here is that you're > trying to do The Wrong Thing. > What you want is an IPv6 class which represents an address in some > canonical form. It would have constructors which accept any of the > RFC-2373 defined formats. It would also have string formatting methods > to convert the internal form into any of these formats. > Then, instead of attempting to regex your way directly from one string > representation to another, you would do something like: > addr_string = "FEDC:BA98:7654:3210:FEDC:BA98:7654:321" > print IPv6(addr_string).to_short_form() This does sound like a more robust solution. I'll give it some thought. Thanks Roy! -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"