This is a really common question. Pregnancy almost always happens when sperm (either cum or pre-cum) gets into the vagina during vaginal sex (penis in the vagina). If some sperm gets into the vagina during rubbing/dry-humping, there is a small risk of pregnancy, even if your penis didn’t go in her vagina.
If you’re worried about pregnancy, your partner should get tested. It’s also a good idea to talk with your partner and a trusted adult like a parent, nurse, or doctor about what kind of birth control might be right for the two of you.