regexp help
John Machin
sjmachin at lexicon.net
Fri May 9 19:52:50 EDT 2008
Paul McGuire wrote:
> from re import *
Perhaps you intended "import re".
> vowels = "aAeEiIoOuU"
> cons = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
> encodeRe = re.compile(r"([%s])[%s]\1" % (cons,vowels))
> print encodeRe.sub(r"\1",s)
>
> This is actually a little more complex than you asked - it will search
> for any consonant-vowel-same_consonant triple, and replace it with the
> leading consonant. To meet your original request, change to:
>
> from re import *
And again.
> cons = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
> encodeRe = re.compile(r"([%s])o\1" % cons)
> print encodeRe.sub(r"\1",s)
>
> Both print "prince".
>
No they don't. The result is "NameError: name 're' is not defined".
More information about the Python-list
mailing list