It's common for the parents of young children and toddlers to feel anxious when they see their child touching their genitals, especially if it is done in a less-than-private setting.
The child's behaviour is perfectly normal.
At a very young age, children begin to explore their bodies by touching, poking, pulling, and rubbing their body parts, including their genitals. Their discovery is propelled by an age-appropriate curiosity about their bodies and is as innocent as their exploration of their fingers and toes.
Around the age of three or four, many children have graduated out of nappies and so have gained greater access to their private parts. They've discovered that touching their genitals is particularly pleasurable and soothing. Unfortunately for parents, young children are normally oblivious to the concept that private parts are called private for a reason. They will often develop a fascination with their genitals and - as with everything else they're learning about - be eager to share their discoveries with others.
So, you may find your preschooler 'playing doctor' with another child around the same age. It's important not to overreact. To them it's just and innocent game - their exploration is scientific not sexual.
Her experiments may look like play to you, but they're actually serious study. - Deborah M. Roffman, a human-sexuality educator and author of But How'd I Get in There in the First Place? Talking to Your Young Child About Sex.
Don't scold your child when they touch themselves - at best this will only prompt a sense of guilt or shame. If it's not an appropriate setting, distract them with a toy or game (after asking if they want to go to the toilet!).
Of course, take the opportunity to explain to your preschooler (later) that even though touching themselves feels good, it should be done in private. Preschoolers are old enough to grasp that some things are not meant to be public.
While your child is busy discovering how their body works and how it makes them feel, try to respect both their inquisitiveness and their privacy. You'll be helping them lay the foundations for more mature forms of physical intimacy and love later in life.