title: Regex: Group OR Group
body: <p>I have a text file coming in, bar-delimited, where a field is supposed to hold city comma state. An example:</p>
  
  <pre><code>|Boston, MA|
  </code></pre>
  
  <p>In my application I need to capture the city and state as two different fields. This is part of a larger Regex to process an entire line, but that part that handles this field is:</p>
  
  <pre><code>\|(.+),(.+[^|]+)\|
  </code></pre>
  
  <p>And this captures the text before the comma into one group and the text after into another group. Works great when the field is filled out as expected.</p>
  
  <p>My problem is that sometimes, this field will come in with either:</p>
  
  <ul>
  <li>NO information between the bars (<code>||</code>)</li>
  </ul>
  
  <p>or
  - Text without a comma (<code>|unknown|</code>)</p>
  
  <p>And I need to modify this regex so that:</p>
  
  <ul>
  <li><p>If there is no information between the bars, I still get 2 groups with blank values</p></li>
  <li><p>If there is a string of text without a comma, that string gets captured as group one, and group 2 is captured with a blank value</p></li>
  </ul>