Hello, MacGyver27 and All
Thinking to your problem, I’ve just imagined a particular search/replacement, that changes the case of each letter, of the replacement word, ACCORDINGLY TO the case of each corresponding letter, in the searched word :-)))
Hypotheses :
The searched and replacement words are supposed made of any word character. That is to say that they may contain possible digit characters and/or any underscore symbol as, for instance, the words TEST_02 or MY_FUNCTION
Three cases are possible :
A) The searched and replacement words have the same size :For instance, if the searched word is device, whatever its capitalization form, and the exact replacement word is SySTeM, here are, below, the results of this S/R, for some forms of the searched word :
DeVIce => SySTem dEVicE => sYSteM devICe => sysTEm dEvIcE => sYsTeM B) The searched word have less letters than the replacement word :For instance, if the searched word is device, whatever its capitalization form, and the exact replacement word is lOCatIOn, here are, below, the results of this S/R, for some forms of the searched word :
DeVIce => LoCAtiOn dEVicE => lOCatIOn devICe => locATiOn dEvIcE => lOcAtIOnNote, in that example, that the 7th and 8th remaining letters, of the replacement word, which cannot be associated to a corresponding letter, in the searched word, keep their initial capitalization form !
C) The searched word have more letters than the replacement word :For instance, if the searched word is device, whatever its capitalization form, and the exact replacement word is TeSt, here are, below, the results of this S/R, for some forms of the searched word :
DeVIce => TeST dEVicE => tESt devICe => tesT dEvIcE => tEsTRemarks :
If a character of the searched word is NOT a letter, the associated character, in the replacement word, will NOT be changed
If a character of the replacement word is NOT a letter, it will NOT be changed, of course !
To perform these capitalization changes, TWO consecutive S/R will be mandatory.
In addition, I need a dummy character, NOT used yet, in your file. I chose the # character, but feel free to chose any other one !
So :
Let M be the number of letters of the SEARCHED word
Let N be the number of letters of the REPLACEMENT word
Then :
For case A) ( M = N ) OR case B) ( M < N )
FIRST S/R :SEARCH (?i)\b<SEARCHED word, in ANY case>\b
REPLACE #<REPLACEMENT word, in ANY case>$0#
SECOND S/R :SEARCH #|(?-is)(?=\w{<N>}(?:(\u)|(\l)))(\w)(?=\w*#)|(?i)<SEARCHED word, in ANY case>#
REPLACE \u(?1\3)\l(?2\3)
For case C) ( M > N )
FIRST S/R :
SEARCH (?i)\b(<The N FIRST letters>)(<The M-N LAST letters>)\b, of the SEARCHED word, in ANY case
REPLACE #<REPLACEMENT word, in ANY case>\1#\2
SECOND S/R :
SEARCH #|(?-is)(?=\w{<N>}(?:(\u)|(\l)))(\w)(?=\w*#)|(?i)<The N FIRST letters>#<The M-N LAST letters> , of the SEARCHED word, in ANY case
REPLACE \u(?1\3)\l(?2\3)
Then, from the examples, above :
For case A), from the original text :
DeVIce
dEVicE
devICe
dEvIcE
SEARCH (?i)\bdevice\b
REPLACE #system$0#
We obtain, after the 1ST S/R :
#systemDeVIce# #systemdEVicE# #systemdevICe# #systemdEvIcE#SEARCH #|(?-is)(?=\w{6}(?:(\u)|(\l)))(\w)(?=\w*#)|(?i)device#
REPLACE \u(?1\3)\l(?2\3)
And, finally, after the 2ND S/R :
SySTem sYSteM sysTEm sYsTeMFor case B), from the original text :
DeVIce
dEVicE
devICe
dEvIcE
SEARCH (?i)\bdevice\b
REPLACE #location$0#
We obtain, after the 1ST S/R :
#locationDeVIce# #locationdEVicE# #locationdevICe# #locationdEvIcE#SEARCH #|(?-is)(?=\w{8}(?:(\u)|(\l)))(\w)(?=\w*#)|(?i)device#
REPLACE \u(?1\3)\l(?2\3)
And, finally, after the 2ND S/R :
LoCAtion lOCatIon locATion lOcAtIonFor case C), from the original text :
DeVIce
dEVicE
devICe
dEvIcE
SEARCH (?i)\b(devi)(ce)\b
REPLACE #test\1#\2
We obtain, after the 1ST S/R :
#testDeVI#ce #testdEVi#cE #testdevI#Ce #testdEvI#cESEARCH #|(?-is)(?=\w{4}(?:(\u)|(\l)))(\w)(?=\w*#)|(?i)devi#ce
REPLACE \u(?1\3)\l(?2\3)
And, finally, after the 2ND S/R :
TeST tESt tesT tEsTBest Regards,
guy038
P.S. : A last example, with my_function_n008 as a searched word and ABCD_123IjklmnOP as a replacement word, which, both, contain 16 characters !
So, Let’s supposed the example text, below :
My_Function_N008 mY_fUNCTION_n008 my_FUNCTION_n008 MY_fUnCtIoN_N008SEARCH (?i)\bmy_function_n008\b
REPLACE #ABCD_123IjklmnOP$0#
We obtain, after this 1ST S/R :
#ABCD_123IjklmnOPMy_Function_N008# #ABCD_123IjklmnOPmY_fUNCTION_n008# #ABCD_123IjklmnOPmy_FUNCTION_n008# #ABCD_123IjklmnOPMY_fUnCtIoN_N008#SEARCH #|(?-is)(?=\w{16}(?:(\u)|(\l)))(\w)(?=\w*#)|(?i)my_function_n008#
REPLACE \u(?1\3)\l(?2\3)
And, after the final 2ND S/R :
AbCD_123ijklMnOP aBCd_123IJKlmnOP abCD_123IJKlmnOP ABCd_123IjKlMnOP