How to safely and legally join building wire behind drywall
The &quot;best way&quot; is to replace all the damaged wire.
Either completely (from where it starts and ends now) or by adding two junction boxes (which must remain accessible) where you can join the undamaged parts of the wire to new undamaged wire between the two junction boxes. If you can reach one end with new wire, you may only need one new junction box.