“I have a type: a**holes. I keep dating a**holes,” said Maggie*, 31.“I keep dating losers that I have to ‘mother,’” sighed Kate, 27.“I keep dating guys with commitment issues,” complained Becky, 38.Sound familiar? “If you seem to have an endless string of failed relationships, then you’ve got to try to figure out why is it [not working out]?” asks Rachel Sussman, couples counselor and author of “The Breakup Bible.”MORE: Sneak Peek at “The Breakup Bible”And the answer can be found in your attachment style. “There’s a science behind it,” explains Amir Levine, M.D., co-author of the tome on attachment style.Understanding Your Attachment StyleYour attachment style is based on the way you bonded with your parents or caregiver back when you were a baby. This bonding evolved into three kinds of attachment styles: secure, avoidant and anxious. (There’s a fourth type, fearful, that’s a combination of avoidant and anxious, but we’ll stick to the basics here.)People with a secure attachment style often give their significant other what they need before they even have to ask because they’re attentive and caring. And the good news is, they’re the majority at roughly 60 percent of people.It’s no surprise that people who are avoidant say they want a relationship, but when they actually get close to someone, they freak out and keep whomever they’re dating at arms length—or in our modern times, make them wait a week before they text again. “They think the problem is that they haven’t found the one and that they will be willing to settle down when they find the right person, even though they’ve been single for forty years!” says Dr. Levine, describing a common form of avoidant behavior.Last but not least, anxious people love closeness so much they’re often obsessed and emotional about every detail of their relationships. Or as Dr. Levine puts it, “they have a very sensitive radar screen.” People who are anxious crave being in a deeply committed relationship.COLUMN: How to Have a Secure Relationship But like doesn’t always fall for like and in many cases, opposites attachment styles attract. Researchers have found that avoidant individuals are often drawn to anxiously attached people, particularly in the anxious female/avoidant male combination. Hence the common laments: “Why does every guy I date turn out to be an emotionally unavailable douche bag?” and “Why is every girl so clingy?”Attachment styles may also partly account for the saying that “nice guys finish last.” Dr. Levine blames part of the problem on avoidant behavior being seen as a manly trait—in other words, the idealized stone-cold cowboy in a movie who stares far off into the distance, stoic and emotionless—rather than the secure, emotionally available, relationship-oriented guy.“When [women] get a man who is compassionate and emotional, all of a sudden they think he’s not masculine enough,” explains Dr. Levine. And the truth is, the majority of men display a secure attachment style and are caring and open. But since our cultural definition of masculinity is so wrapped up in avoidance, women are prone to fall for men who treat them badly if they think that’s what’s normal.MORE: Are You Dating These Avoidant Dudes?Adding fuel to the fire, “a lot of times people who are avoidant tend to be less expressive in their faces and tend to be more stoic,” notes Dr. Levine. “And if you’re [an anxious attacher and] already into that whole cycle, you tend to get turned on by that.”Well, that explains why unshakable racer Ryan Gosling looked so delicious in “Drive.”It’s pretty twisted, but in some ways, both the avoidant and the anxious person are getting what they need out of an undesirable relationship together. Dr. Levine and his “Attached” co-author, psychologist Rachel Heller, explain this phenomenon by arguing that, “each reaffirms the other’s beliefs about themselves and about relationships.” The avoidant one is proven right to be independent because others demand too much from them. And the anxious one is let down again, validated in their belief that they can’t get the intimacy that they need. According to “Attached,” “So, in a way, each style is drawn to reenact a familiar script over and over again.”If you have an anxious attachment style and are dating someone who is avoidant, it’s easy to believe that relationships are a rollercoaster ride with tough lows and thrilling highs. Explains Dr. Levine: “It’s that pounding sort of feeling of: ‘I’m waiting for a phone call and they’re not calling. What’s going on? They’re not interested in me?’ Then they call and you feel euphoric.”This pattern leads a person to a huge misunderstanding of passion. “They mistakenly think anxiety is love, but it’s completely not true,” he notes. However, it is easy to see why the exciting cycle can be so addictive. But how do you quit it like a bad habit?Discover Your Own Attachment StyleWhen it comes to relationships, ignorance is not bliss. Knowledge is power, and in this case, it’s most likely what you need to feel in control of your love life. So first, assess your attachment style. (Try our scientifically-validated Close Relationships Quiz to uncover your own attachment style.) If you’re with someone, you can even put your partner to the test. Don’t worry about the results of your attachment style test—just be honest with yourself. And rest assured—there is someone for everyone!QUIZ: What’s Your Attachment Style?“If you start to understand [your attachment style], then you can really see the cycle,” Dr. Levine points out. And you’re not going to make the same mistakes and get caught on that same kind of guy rollercoaster mindlessly because you’ll know better.Break Out of a Bad Dating RutThe next step? Keeping your eyes open for red flags when you’re dating. It’s foolish to put on blinders in your personal life, especially when you wouldn’t put them on in your professional life. If you were interviewing someone for a job and they were wishy-washy about the work and didn’t seem to have the necessary skills, “then would you still hire them thinking it would work out?” asks Dr. Levine. “I don’t think so.” So why is the hiring policy in your heart more lenient on unqualified and unenthusiastic candidates?“If you pay attention, everyone will reveal whatever you need to know about them by the third or fourth date,” says Sussman. Red flags included. She points out some things to look out for: Is he checking other women out? Is he nasty to wait staff? Is he contacting you with regularity? Did he say he wants to be in a committed relationship?MORE: What We Learn from Speed Dating StudiesDr. Levine suggests you check your answers against the one big question about your relationship: “What’s life like in their ‘inner circle?’” Use your brain, not your heart or your stomach with the butterflies in it, to answer. “If you’re with someone who is secure, you’re being treated like royalty,” he says. “If you’re with someone avoidant, you’re being treated like the enemy—they don’t want to tell you things, you pry too much, you’re too needy.” With someone anxious, you’re getting a lot of attention but you might find yourself pulling away.Change Your Relationship PatternsBut if you’re feeling caught in the seemingly endless cycle of bad relationships, Sussman recommends taking a break. “If you feel that dating is effecting your self-confidence in a negative way, stop dating for a while and get back to doing something that’s exciting to you,” she suggests. “Join a sports team, climb a mountain, travel, take a class, write a book—do something interesting. And when you feel great about yourself, get back out there again.”GALLERY: Famous Characters & Attachment StylesLexie, 29, was able to change her pattern, with that very advice. For three years, she had kept praying for the same kind of man: “I really wanted someone in a suit,” she says.After many heartbreaks, she decided to travel to regain her sense of self and make a change. However, when she returned from her trip, she found herself on a date with the same old kind of guy. But this time it was different. After he ignored her on a date to chat with other women at the bar, “I realized I was starting to feel crazy,” she admitted. With him, “I was apologizing more,” she recalls. “I wasn’t feeling that happy about myself. I was catering to him, asking him all the questions.” Red flag alert!Her newfound self-awareness and self-assuredness allowed her to pick herself up and leave. And later that night, amazingly enough, she wound up meeting a “goofy guy,” the “man of her dreams” and her current boyfriend. “Initially he wasn’t my type at all, but now it’s a perfect fit,” she gushes. “He’s taught me so much about love, and being supportive and cooking.”Adds Dr. Levine, “the beauty of attachment style is that they’re stable, but they’re malleable.” If you’re not the secure type, you can grow to become secure by feeling supported and learning from your secure partner. “It’s almost like you have a built in relationship coach in your relationship,” he says. “For both anxious and avoidant [people], the fastest way to become secure is to be with someone secure.”So how do you spot one of these magical secure people? “It’s really true from date number one,” Dr. Levine has found. “The people who are consistent and are secure, they tell you they like you, they tell you they want to meet you again.” They’re not gun, er, relationship-shy.If a secure dream lover proves elusive and you find yourself on a lot of first dates with no-goodniks, be careful not to let it get you down. “Don’t overly blame yourself,” Sussman warns. “You have to keep going and not let it hurt your self-esteem.” This pattern of dating jerks is common, she admits. “Listen, that’s why they have the expression you’ve got to kiss a bunch of frogs before you get your prince,” says Sussman.QUIZ: How’s Your Self-Esteem?Keep dating until you find someone who isn’t slimy—and is a real prince of a guy. *Names have been changed.