^(all|contact|all,contact|contact,all)$
do not allow all,all or contact,contact or all,contact,all, etc.
I need to be able to have an equivalent pattern, but I want to reduce because I may have more elements in the future and finding all possible combinations would be difficult.
eg with 3 elements
^(all|contact|another|all,contact|contact,all|all,another|another,all|all,another,contact|all,contact,another|contact,all,another|contact,another,all|another,all,contact|another,contact,all)$
It should accept one word or multiple words separated by commas and each word only appears once. Thanks for the help in advanced.
^(?!.*\b(\w+)\b.*\b\1\b)(?:another|contact|all)(?:,(?:another|contact|all))*$might do.