Big thing to remember is that foreclosure does not mean you can't buy another home, it just limits the lenders you can use if you want to buy one within the 2-5 years.
In general, the guidelines for waiting to apply for a mortgage after a foreclosure are as follows:
Conventional Mortgages: Up to 7 years
FHA Mortgages: Up to 3 years
USDA Mortgages: Up to 3 years
VA Mortgages: Up to 2 years
If at all possible, consider a short sale or a deed-in-lieu of foreclosure. Your wait times in some cases will be less.
However, if you are interested for yourself than the best thing you can do is approach a mortgage lender right away so you know exactly what is needed if you would like to purchase a home.
And also keep in mind this is for traditional lending. You can always do a land contract or rent-to-own and negotiate directly with the seller. You want a real estate attorney on your team for this path to ensure you know the differences between each and your rights most importantly. If you are someone who thinks home values will be higher in 3 years than what is current this could be an option.