|Keep It Simple, Stupid|
Preserve Case in Regexpby stefan k (Curate)
|on Mar 16, 2004 at 10:30 UTC||Need Help??|
stefan k has asked for the
wisdom of the Perl Monks concerning the following question:
I just ran into the problem of renaming a C++ class throughout many files. The class-name was in camel case (say TheClass) whereas the filenames were lower case (theclass.cc). The bundle came with a Makefile and naturally I wanted to replace the names in there, too.
The renaming of the files was done using mmv.
And for the contents of the files I wanted to use that favorite perl-one-liner:
And, yes, I could have done this for every possible case, but I wondered whether all that could be done in one line. After reading man perlre and surfing the Monastery I finally found one solution at Re: Regex: Case insensitive search but case sensitive replace.
But, honestly, this can't be it, can it?
I'd appreciate a "I" modifier (or something like that) for regexeps that means "preserve case" very much like the (X)Emacs variable case-replace does it. It would match case insensitive but perform some magic to the replacement in that it would preserve the case of the matched pattern there.
I am well aware that this would be quite hard for replacements that have a different length from the search pattern. Still, even then the cases at some prominent positions (like the first or the last character or characters after a grouping construct, etc) could be figured out.
Is that possible or already existing, or already planned? Am I missing something here?
In expectation of deeper enlightenment and with many thanks...