 <p>You can do something like this (starting with Lloyd's original regex):</p> <pre><code>^(?:(?:CN|OU|DC)\=\w+,)*(?:CN|OU|DC)\=\w+$ </code></pre> <p>Match zero or more groups followed by a comma, then one final group.</p> <p>If you want to require there at least be two total groups, just change <code>*</code> to <code>+</code>:</p> <pre><code>^(?:(?:CN|OU|DC)\=\w+,)+(?:CN|OU|DC)\=\w+$ </code></pre> <p>If you want to require that the number of groups is within a certain range, use a quantifier:</p> <pre><code>^(?:(?:CN|OU|DC)\=\w+,){1,3}(?:CN|OU|DC)\=\w+$ </code></pre> <p>This would require between two and four groups total.</p> <p>If you have other requirements that you want to enforce (such as always must contain DC, or has at least two DC if OU and CN are absent), then you are asking too much of a single regex. You will need a multi-step approach.</p>