title: preg_match_all with multiple OR conditions
body: <p>Im trying to create a single regex pattern to match a string where 2 fields (separated by a comma) could either be</p>
  <ul>
  <li>a) empty,</li>
  <li>b) a single word, or</li>
  <li>c) 2 words separated by a backslash (\).</li>
  </ul>
  <p>This is a log file where position 1 is a source username field and position 2 is a destination user field, but both could be separated with a backslash if domain name is present (domain\username)</p>
  <p>I've tried everything I can think of and can get 2 out of 3 to match, but not all conditions. Below are the possible variants that this string could be in. (something1 and something2 are known patterns that occur before and after this condition)</p>
  <blockquote>
  <p>something1,,,something2</p>
  <p>something1,,dstuser,something2</p>
  <p>something1,,dstdomain\dstuser,something2</p>
  <p>something1,srcdomain\srcuser,,something2</p>
  <p>something1,srcdomain\srcuser,dstdomain\dstuser,something2</p>
  <p>something1,srcuser,dstdomain\dstuser,something2</p>
  <p>something1,srcuser,dstuser,something2</p>
  <p>something1,srcuser,,something2</p>
  <p>something1,srcdomain\srcuser,dstuser,something2</p>
  <p>something1,srcdomain\srcuser,dstdomain\dstuser,something2</p>
  </blockquote>
  <p>For example, I've tried this:</p>
  <pre><code>^.*something1,(,|(?J)(?&lt;src_username&gt;[^\\]*),|(?&lt;src_domain&gt;.*?)\\(?&lt;src_username&gt;[^\\]*),).*?,something2*
  </code></pre>
  <p>this matches <em>some</em> of the time, but I'm curious if this is possible with a single line of regex.</p>
  <p>Thanks in advance....</p>