See for instance this post Extracting mesh regions for gmsh mesh . Or this turtorial here (might be slightly out of date)