Robust regex

Benjamin Kaplan benjamin.kaplan at case.edu
Mon Nov 19 21:41:31 CET 2012


On Nov 19, 2012 12:37 PM, "Joseph L. Casale" <jcasale at activenetwerx.com>
wrote:
>
> Trying to robustly parse a string that will have key/value pairs separated
> by three pipes, where each additional key/value (if more than one exists)
> will be delineated by four more pipes.
>
>     string = 'key_1|||value_1||||key_2|||value_2'
>     regex = '((?:(?!\|\|\|).)+)(?:\|\|\|)((?:(?!\|\|\|).)+)(?:\|\|\|\|)?'
>
> I am not convinced this is the most effective or safest, any opinions
would
> be greatly appreciated!
>
> jlc
> --
> http://mail.python.org/mailman/listinfo/python-list

Do you even need a regular expression for this? Just split on |||| and then
split those on |||.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121119/5f956d59/attachment.html>


More information about the Python-list mailing list