Detecting hiding communities is considered as a main topic in complex networks. In this article, we propose a multi-swarm elephant herding optimization (EHO) algorithm to uncover community structures in complex environments. It adapts EHO algorithm to community detection problem. EHO algorithm relies on two procedures which are updating clan procedure and separating procedure. The main idea of our multi-swarm approach is that the population is composed of a set of interacting clans. In each clan, a local search function is defined to determine best local individual called matriarch.Through updating clan procedure, the remaining individuals in the clan update their positions based on the matriarch position. In addition, to ensure significant individuals in the clan, a multi-swarm cooperative algorithm is designed to implement separating procedure; clans interchange individuals to balance the exploration and exploitation abilities. A series of experiments are carried out on artificial and real networks. The results obtained by the proposed approach are better than the results obtained by some other approaches.