title: Regex - match an optionally repeated pattern of capture groups
body: <p>Appologies for not knowing exactly how to word this question. There is probably even a better title. I'm open to suggestions.</p>
  <p>I have the following subjects:</p>
  <pre><code>(Field1 = 'Value1') and (Field2 = 'Value2')
  </code></pre>
  <p>and</p>
  <pre><code>(Field1 = 'Value1') and (Field2 = 'Value2') or (Field3 = 'Value3')
  </code></pre>
  <p>I want to match in such a way that I have each thing between the () in groups and each conjunction in a group. So, for the second one, some variation of</p>
  <pre><code>0: Field1 = 'Value1'
  1: and
  2: Field2 = 'Value2'
  3: or
  4: Field3 = 'Value3'
  </code></pre>
  <p>The good news is, I've got regex that works on the first:</p>
  <pre class="lang-regex prettyprint-override"><code>\(([A-Za-z0-9\s\'=]+)\) (and|or) \(([A-Za-z0-9\s\'=]+)\)
  </code></pre>
  <p><a href="https://regex101.com/r/hMXAXS/1" rel="nofollow noreferrer">https://regex101.com/r/hMXAXS/1</a></p>
  <p>But (on the second subject) it doesn't match the third &quot;and ()&quot;. I need to support arbitrary numbers of groups. I can modify it to just look for &quot;and ()&quot; but then it doesn't match the first group.</p>
  <p>How can I tell regex to do this? I either need to &quot;double count&quot; some groups (which is fine) or have some other way of optionally looking for additional patterns and matching them.</p>
  <p>Thanks for the help!</p>
  <p>PS: I was able to get my application to work with the regex <code>((and|or) \(([A-Za-z0-9\s\'=]+)\))+</code> and then just accepting that the first group would never match and creating application logic to support this. Still, I'd bet there's a better way.</p>