String splitting with exceptions

John Levine johnl at iecc.com
Wed Aug 28 17:35:16 EDT 2013


>Can you have brackets within brackets? If so, this is impossible to deal
>with within a regex.

Nope.  It's a regular language, not a CFL.

>Otherwise:
>>>> re.findall('((?:[^[:]|\[[^]]*\])*):?',s)
>['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '', '']

That seems to do it, thanks.

-- 
Regards,
John Levine, johnl at iecc.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. http://jl.ly



More information about the Python-list mailing list