A method of gauge-invariant regularization