Sit on the floor with the leg to be stretched extended, and the other leg bent with the foot towards your body.
Reach out with your hands, lean your upper body forward, and bring your chest towards your thigh.
Make sure you don't round the upper back, and your lower back should be slightly curved.
Get to the point of a mild stretch and hold.
Repeat for each leg
Notes
There are several different stretching exercises for the hamstrings, see also hamstring stretch standing and supine.
A version of this stretch called the 'hurdler's stretch' is similar except that the bent leg is the other way around. This stretch may lead to injury and should be avoided, as it stretches the medial ligaments of the knee and crushes the knee meniscus