Hey all,
related question: http://stackoverflow.com/questions/919056/python-case-insensitive-replace
What's the best way to do a case insensitive replace WITHOUT HURTING THE CACHE in the re module? I'm monitoring carefully the cache to make sure my favorite regexes stay there (speed, of course).
I just notice that my code:
ner_token_result = re.sub('(?i)'+leftover, corrected_word, ner_token_result)
is re.compiling every time it is run. leftover
is dynamic (based on user input).
I like regular expressions (fast, I can read them) but I don't want to hurt my cache.
I don't want to use a caseless string class...
I don't want the ugliness of converting to lowercase, replacing and restoring case...
Please help?