Weakly nonlinear extension of d'Alembert's formula