String splitting with exceptions
Neil Cerutti
neilc at norwich.edu
Wed Aug 28 14:18:11 EDT 2013
On 2013-08-28, Tim Chase <python.list at tim.thechases.com> wrote:
> 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.
Good point. My little parser fails on that, too. It'll miss *all*
final fields. My parser needs "if s: yield s[b:]" at the end, to
operate like str.split, where the empty string is special.
--
Neil Cerutti
More information about the Python-list
mailing list