Try:
Func: "Upper-case text then Title-case it"
Code:
from calibre.utils.icu import upper
from calibre.utils.titlecase import titlecase
from calibre.ebooks.oeb.polish.utils import apply_func_to_match_groups
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
'''Title-case matched text. If the regular expression contains groups,
only the text in the groups will be changed, otherwise the entire text is
changed.'''
text = apply_func_to_match_groups(match, upper)
'''Now return it titlecased.'''
return titlecase(text)