Discrimination is associated with mental health problems. While prior research has demonstrated the significance of emotion regulation in explaining the onset and development of discrimination-related anxiety, few studies investigated this dynamic with cognitive flexibility among sexual and/or racial minority individuals. The current study incorporated cognitive flexibility to investigate its potential buffering effects on discrimination-related anxiety. 221 individuals, 37.6% of whom (n = 83) identified as sexual and/or racial minorities, responded to an online questionnaire about their levels of cognitive flexibility and emotion regulation, perceived discrimination, and anxiety. Moderated mediation analyses were conducted with these variables. Our findings indicated that emotion regulation difficulty (ERD) mediated the relationship between discrimination and anxiety, while cognitive flexibility had a strong moderating effect on the relationship between ERD and anxiety. These results suggested new research directions and implied the therapeutic potential of advancing cognitive flexibility skills with emotion regulation training in depression and anxiety intervention and treatments. Future research is needed to investigate cognitive flexibility as a transdiagnostic mechanism underlying the onset and development of anxiety, to potentially lead to novel prevention or intervention for marginalized people facing additional stressors like discrimination.