<?xml version="1.0" encoding="windows-1252"?>
<node id="336968" title="Preserve Case in Regexp" created="2004-03-16 05:30:19" updated="2005-06-03 11:46:15">
<type id="115">
perlquestion</type>
<author id="5094">
stefan k</author>
<data>
<field name="doctext">
Fellow Monks,
&lt;p&gt;
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.
&lt;p&gt;
The renaming of the files was done using &lt;code&gt;mmv&lt;/code&gt;.
&lt;p&gt;
And for the contents of the files I wanted to use that favorite perl-one-liner:
&lt;code&gt;
perl -pi.bak -e 's/theclass/thenewclass/'
&lt;/code&gt;

And, yes, I &lt;em&gt;could&lt;/em&gt; have done this for every possible case, but I wondered whether all that could be done in one line. After reading &lt;code&gt;man perlre&lt;/code&gt; and surfing the Monastery I finally found one solution at [id://307638].  
&lt;p&gt;
But, honestly, this can't be it, can it?
&lt;p&gt;
I'd appreciate a "I" modifier (or something like that) for regexeps that means "preserve case" very much like the (X)Emacs variable &lt;code&gt;case-replace&lt;/code&gt; 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.
&lt;p&gt;
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.

&lt;p&gt;
Is that possible or already existing, or already planned?  Am I missing something here?
&lt;p&gt;
In expectation of deeper enlightenment and with many thanks...

&lt;div class="pmsig"&gt;
&lt;div class="pmsig-5094"&gt;
&lt;p&gt;
&lt;table width="80%" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td&gt;&lt;small&gt;Regards...&lt;/small&gt;&lt;/td&gt;
&lt;td align="right"&gt;&lt;small&gt;
&lt;a href="http://www.skamphausen.de"&gt;Stefan&lt;/a&gt;
&lt;/small&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="2" align="center"&gt;
&lt;small&gt;you begin bashing the string with a +42 regexp of confusion&lt;/small&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
