The replacement of raw materials in formulations is a crucial but challenging issue in industrial production. The goal is to substitute the inadequate or costly raw materials or their combinations with the adequate or potentially adequate inventory but while still ensuring the consistency and stability of product quality. In the present study, near-infrared (NIR) technology is first used for rapid and non-destructive analysis and further comprehensive characterization of the chemical characteristics of different raw materials. Afterwards, the particle swarm optimization (PSO) method is modified for the processing of NIR data and formulation replacement. Under the conditions of optimal constraints, an integrated strategy for replacement and optimization of raw materials in formulation is fully established. This yields optimized results for replacements that meet real demands in formulation design. In addition, the simulation of NIR spectra is initially realized by combining multiple Gaussian functions, which constructs simulated datasets that are suitable for verifying the accuracy and reliability of the proposed method. The real example of the replacement of raw materials is applied to comprehensively demonstrate the effectiveness and capability of the strategies proposed in this study. Among the 3,000 combinations used for formulation replacement, the recommended results obtained through the PSO method exhibit a high targeted proportion, attaining 81.82%, in which the difference between the optimal and original formulation is less than 0.0005. The results of expert validation indicate that 83% of the evaluations are consistent with spectral similarity assessments, which shows that the replaced results effectively meet the requirements for objective, scientific and digitized requirements in product manufacturing. Furthermore, this proposed method is applicable to various analysis and application scenarios on the basis of NIR analysis and global optimization.