Case Matching Find Replace
APL (Dyalog), 75 73 72 bytes



Prompts for T, R, and F in that order. R must b given in Dyalog transformation format and F must be given in PCRE format.

⍞⎕R(⍞∘{(⊣⌿d)l¨⍨(1∘⌷≠(⊢⌿d∊⎕A,l⎕A)∧≠⌿)d≠(l←819⌶)d←↑⍺⍵.Match↑¨⍨≢⍺})⍠1⊢⍞


Try it online!

⍞ prompt for T

⊢ yield that (separates 1 and T)

⍞⎕R(…)⍠1 prompt for F and Replace matches with the result of the following function:

 ⍞∘{…} derive a monadic function by tying the prompted-for R as left argument to:

  ≢⍺ count the number of letters in R

  ⍺⍵.Match↑¨⍨ take that many letters from each of R and the match
   ⍺ is the left argument, which we tied R as.
   ⍵ is a namespace in which Match contains the currently found string.

  ↑ mix those two into a two-row matrix

  d← store as d

  (…)  apply the following tacit function to that:

   819⌶ lowercase (mnemonic: 819 looks like Big)

   l← store that function as as l

  d≠ Boolean where d differs (i.e. gives 0/1 for each lowercase/uppercase letter)

  (…) apply the following tacit function to that:

   ≠⌿ vertical XOR

   (…)∧ Boolean AND with the following array:

    l⎕A lowercased Alphabet

    ⎕A, prepend uppercase Alphabet

    d∊ Boolean for each letter in d whether a member of that (i.e. whether a letter)

    ⊢⌿ last row i.e. for character of the match whether it is a letter

   1∘⌷≠ XOR with the first row, i.e. whether each character of R is uppercase

  (…)l¨⍨ use that to lowercase (if 0) or uppercase (if 1) each letter of:

   ⊣⌿ the first row, i.e. R



* Byte count for Dyalog Classic using ⎕OPT  instead of ⍠.