How can I use a regex OR condition to match multiple optional parts in a string, like "part1", "part2", or both?

I’m using regular expressions to validate input and want the user to enter either “part1”, “part2”, or “part1, part2”. I tried ^(part1|part2)$, but it only works for one or the other. Is there a way to use a regex OR condition that allows matching “part1”, “part2”, or both together in any order?