re.split question

bragib at my-deja.com bragib at my-deja.com
Thu Jun 22 08:53:23 EDT 2000


Steffen:

Are you sure you need to use re to do this?  What about:


>>> import string
>>> t = 'uid=joe, ou=orgunit, o=some\\org'
>>> string.split(t, ',')
['uid=joe', ' ou=orgunit', ' o=some\\org']



In article <m3k8fiosky.fsf at gondolin.beleriand>,
  Steffen Ries <steffen.ries at sympatico.ca> wrote:
> Hi,
>
> I'm trying use re.split to separate an LDAP Distinguished Name into
> its naming components. The naming components are of the form
> "attr=value" and they are separated by ",".
>
> The part, which I can't solve is, that "value" may contain the
> sequence "\,", which obviously does not separate a naming component.
>
> e.g.
> "uid=joe, ou=orgunit, o=some org"
> should be split into ["uid=joe", "ou=orgunit", "o=some org"]
>
> "uid=joe, ou=org\\, unit, o=some org"
> -> ["uid=joe", "ou=org\\, unit", "o=some org"]
>
> Is there a way to use re.split to achieve this? (I solved it searching
> [^\\], and splitting the string in a loop, but I was wondering if it
> can be done easier.)
>
> TIA,
> /steffen
> --
> steffen.ries at sympatico.ca	<> Gravity is a myth -- the Earth sucks!
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list