Selecting and masking hair on a solid background isn't too terribly difficult, but doing it over a non-uniform, complex background can be very hard. This great tutorial will show you how to select and mask a subject's hair and convincingly composite it into another image.
Coming to you from Jesus Ramirez of the Photoshop Training Channel, this tutorial will walk you through the process of selecting and masking hair from complex backgrounds using Photoshop. The problem is often two-fold: first, having a non-uniform background means there are some areas that work well with certain selection techniques and tools and others that work with others, thereby making no one tool the complete solution. The other issue is that there will very often be areas that are simply too close in color and/or luminosity to efficiently and effectively separate them from the background. As such, instead of trying to precisely select every single strand (and very likely driving yourself crazy in the process), it's better to use a combination of selection and compositing or simply painting hair back in to make it realistic again. It's a balancing game of getting as much of the original hair as possible before you hit diminishing returns.