Take three inputs, a string of text, T
; a string of characters to replace, F
; and a string of characters to replace them with, R
. For each substring of T
with the same (case insensitive) characters as F
, replace them with the characters in R
. However, keep the same case as the original text.
If there are more characters in R
than F
, the extra characters should be the same case as they are in R
. If there are numbers or symbols in F
, then the corresponding characters in R
should keep the case they have in R
. F
will not necessarily appear in T
.
You can assume all text will be in the printable ASCII range.
Examples
"Text input", "text", "test" -> "Test input"
"tHiS Is a PiEcE oF tExT", "is", "abcde" -> "tHaBcde Abcde a PiEcE oF tExT"
"The birch canoe slid on the smooth planks", "o", " OH MY " -> "The birch can OH MY e slid OH MY n the sm OH MY OH MY th planks"
"The score was 10 to 5", "10", "tEn" -> "The score was tEn to 5"
"I wrote my code in Brain$#@!", "$#@!", "Friend" -> "I wrote my code in BrainFriend"
"This challenge was created by Andrew Piliser", "Andrew Piliser", "Martin Ender" -> "This challenge was created by Martin Ender"
// Has a match, but does not match case
"John does not know", "John Doe", "Jane Doe" -> "Jane does not know"
// No match
"Glue the sheet to the dark blue background", "Glue the sheet to the dark-blue background", "foo" -> "Glue the sheet to the dark blue background"
// Only take full matches
"aaa", "aa", "b" -> "ba"
// Apply matching once across the string as a whole, do not iterate on replaced text
"aaaa", "aa", "a" -> "aa"
"TeXT input", "text", "test" -> "TeST input"
"TeXT input", "text", "test"
\$\endgroup\$"The birch canoe slid on the smooth planks", "o", " OH MY "
so humorous, but I loved that example. \$\endgroup\$