Using a function for regular expression substitution

Roy Smith roy at
Sun Aug 29 17:10:37 CEST 2010

In article 
<9170aad0-478a-4222-b6e2-88d00899d8b4 at>,
 naugiedoggie <michael.a.powe at> wrote:

> Hello,
> I'm having a problem with using a function as the replacement in
> re.sub().
> Here is the function:
> def normalize(s) :
>     return
> urllib.quote(string.capwords(urllib.unquote('provider'))))

I read though this entire post, and I'm not quite sure what you're 
asking.  May I suggest that you need to break this down into smaller 
pieces and find a minimal test case.

I'm guessing this is a problem with the regex processing.  To prove 
that, strip away everything else and verify that part in isolation.  
Compile your regex, and match it against a string that you expect it to 
match.  Then, examine the groups returned by the match object.  If 
they're not what you expect, then re-post your question, with just this 
minimal test code.

More information about the Python-list mailing list