RegExp, Python and strings

Aahz Maruch aahz at netcom.com
Sat Jan 8 10:12:54 EST 2000


In article <857hhb$3kmi$1 at www.univie.ac.at>,
Matthias Huening <matthias.huening at univie.ac.at> wrote:
>
>In PERL I can do things like this (in one line):
>$A = "Rossum, Guido van; Harms, Daryl; Python, Franz-Josef";
>$A =~ s/([A-Z])[\w]+(?![ \w\-]+,)([ ;-]|$)/$1.$2/g;
>This RegExp results in: "Rossum, G. van; Harms, D.; Python, F.-J."
>
>Now I am trying to rebuild this in PYTHON, but I can't get it to work.
>Any hints? Should I keep trying? Or should I stick to PERL for those
>kinds of string-manipulations?

You should be able to do that with re.sub(), but the syntax is slightly
different.  Don't forget to use raw strings, though (e.g. r'\w').
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

The problem with an ever-changing .sig is that you have to keep changing it.



More information about the Python-list mailing list