Generally by not gambling anything that I wouldn't be okay with losing.
This is the golden rule. I only bet a fixed amount every week on sports and if I lose I lose and wait until the next week. I'm currently a few hundred in profit this season and have never had any net losses so far so I don't know the feeling of losing a substantial amount but I know how any loses can make you feel and the buzz you get from winning but if you can't handle these you have a problem. If you think gambling has become a problem for you which it looks like it has I'd just really try learn from the experience and cut your loses before it gets worse. You might have lost all your money now but you can lose even more or even get into debt.