re

Maxim Khesin max at cNvOiSsiPoAnMtech.com
Fri Jan 2 21:03:55 CET 2004


I am studying the re module and still do not understand how to do some 
really simple tasks:
1) say I need to capitalize any word that is between the words 'United' 
and  'of America'. So I do
re.findall|match|search('United .* of America', s)
this may return 'United States of America', but not 'States', which is 
the word of interest.
2) There is a further problem:
even if I had a way to specify 'States' in the example above as the 
matched regex, the sub function proves insufficient: re.sub allows me to 
specify only the replacement string, but not a operator:
re.sub(pat, lambda pat: Capitalize(pat), str)
would have been much more powerful.

are there ways to use re that I missed? is there another module that can 
do these?

thanks,
max.




More information about the Python-list mailing list