The transformation of salvianolic acid B brought on by heat treatment recovery of ethanol eluent, which is a difficult problem in pharmaceutical technology, affects the purity of raw material when the medicinal raw material salvianolic acid B is purified by resin. Ultrasonic-assisted nanofiltration separation (UANS) was first employed to improve efficiency of resource utilization by regulating rejection and separating salvianolic acid B and rosmarinic acid from organic pharmaceutical wastewater. The rejection was related to three variables: ultrasonic power, pH, and ethanol concentration. But there were differences in the effects of variables on the rejections of salvianolic acid B and rosmarinic acid. The rejections of rosmarinic acid and salvianolic acid B showed a decreasing trend with an increase in ultrasonic power or a decrease in pH; however, when the concentration of ethanol was increased from 5 % to 35 %, the salvianolic acid B rejection increased from 84.96 % to 96.60 % and the rosmarinic acid rejection decreased from 35.09 % to 17.51 %. On the basis of response surface methodology (RSM), the optimal UANS parameters for solution conditions involving different ethanol concentrations are as follows: 10 % ethanol solution (ultrasonic power 500 W and pH 6.15), 20 % ethanol solution (ultrasonic power 500 W and pH 6.54), and 30 % ethanol solution (ultrasonic power 460 W and pH 6.34). The molecular proportions of salvianolic acid B were 10.75 %, 7.13 %, and 8.27 % in 10 %, 20 %, and 30 % ethanol wastewater, while the molecular proportions of rosmarinic acid were 40.52 %, 33.83 %, and 69.87 %, respectively. And the recoveries of salvianolic acid B in 10 %, 20 %, and 30 % ethanol wastewater were 93.56 %, 95.04 %, and 97.30 %, respectively, while the recoveries of rosmarinic acid were 3.19 %, 2.27 %, and 0.56 %. The molecular proportion and the rejection are correlated exponentially. In comparison with conventional nanofiltration separation (CNS), UANS is able to resolve the conflict between rosmarinic acid and salvianolic acid B in pharmaceutical wastewater, as well as enhance resource recycling and separation efficiency to prevent pollution of the environment from pharmaceutical wastewater. Experiments using UANS at different power intensities suggest that the ultrasonic at a power intensity of 46–50 W/L and the power density of 0.92–1.00 W/cm2 may resolve the separation conflict between rosmarinic acid and salvianolic acid B. This work suggests that UANS may be a significant advancement in the field of ultrasonic separation and has several potential uses in the water treatment industry.