All too often we see people sticking their leg up as high as they can on something, bend forward, and say they're stretching their hamstrings. In reality, this person is hanging on passive structures, stretching their nerves, and probably pissing off their low back.
There are better ways to stretch your hamstrings! One of the easiest ways to stretch a muscle is to add a load to it. Another way to term this is to perform eccentric muscle actions. The hamstrings extend the hip and flex the knee - thus you want to perform movements that load the hip into flexion with the knee in extension.
Here are two exercises that are great to perform before leg day, running, or any type of sport. Most sport-related hamstring strains are due to an extreme uncontrolled stretch. Priming the hamstrings before activity and learning to actively control motion at end ranges is a way to prehab those hammys. Be sure to limit pelvis and low back motion, keep the ribs pulled down, and breathe through the exercises