What would be a proper way - best practice - to replace a word (character sequence) in a String with another, yet preserve the case of the original? Specifically, if the original is all uppercase, the replacement word should be as well. If the original is all lowercase, the replacement word should be as well. If the original begins with an uppercase character, and the rest is lowercase, the replacement word should be as well.
I presently implement this with three conditional checks, which works fine for my purposes. But it seems to me that there must be a better 'best practice' way, possibly, but not necessarily, with regex. This is meant to be a discussion of possible best or better practice for edification of existing best practice, not a solicitation to solve a trivial coding issue that is already solved and implemented.
A concrete example. In an application that can be run on multiple platforms, all strings containing "click" would be translated to "tap" when run on a mobile device, as would "Click" become "Tap", and "CLICK" become "TAP". In my own case, I do this in a far more general way with a map of words and their replacements, but that is an example of a specific.