I often see “replace with” and “replace by” used interchangeably, but this doesn’t sound right to me:
I replaced that component by this one.
I would use “with” in such a sentence. “By” only seems reasonable in passive, although “with” sounds like it would there work too:
That component was replaced by this one.
That component was replaced with this one.
In my native language, the equivalent of “replace by” can only be used in passive, and even then it’s a bit weird unless a person is the object replacing something – perhaps this affects my judgment?
Web searches haven’t come up with anything conclusive; the results are contradictory and speculative at best.
Are “replace with” and “replace by” interchangeable in active context? What about passive? Are there stylistic reasons to prefer one over the other?
OP is right to suspect active/passive has a bearing on preferred usage. From Google Books…
To be honest, I can’t say I think there’s anything wrong with the "less favoured" versions above, and it would be ridiculous to suggest there’s any semantic difference. But note that whereas…
Tom replaced Dick by Harry
Tom replaced Dick with Harry
…are both equivalent (manager Tom took Dick off the team, and put Harry in instead), if we want to put that into the "passive" voice, we can only recast it as…
Dick was replaced by Tom with Harry
…or (more likely, imho)…
Dick was replaced with Harry by Tom
That’s to say, if the "passive" form actually specifies the "agent", we have to use by for that agent. So we can only use with for the "replacement" in such (slightly contrived) constructions.
1 Google Books has changed somewhat since I originally did these searches – the smaller values are easy to count so they’re accurate, but the "at least" values just reflect how many pages of 10 hits each I could scroll through before GB stopped returning any more (sometimes it just truncates relatively large result sets for no obvious reason). Whatever – that huge reversal of ratios is still unmistakable.