String splitting with exceptions

Tim Chase python.list at tim.thechases.com
Wed Aug 28 13:32:46 EDT 2013


On 2013-08-28 13:14, random832 at fastmail.us wrote:
> On Wed, Aug 28, 2013, at 12:44, John Levine wrote:
> > I have a crufty old DNS provisioning system that I'm rewriting
> > and I hope improving in python.  (It's based on tinydns if you
> > know what that is.)
> > 
> > The record formats are, in the worst case, like this:
> > 
> > foo.[DOM]::[IP6::4361:6368:6574]:600::
> 
> Otherwise:
> >>> re.findall('((?:[^[:]|\[[^]]*\])*):?',s)
> ['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '', '']
> 
> I'm not sure why _your_ list only has one empty string at the end.

I wondered that.  I also wondered about bracketed quoting that
doesn't start at the beginning of a field:

  foo.[one:two]::[IP6::1234:5678:9101]:600::
          ^
This might be bogus, or one might want to catch this case.

-tkc




More information about the Python-list mailing list