title: Bash Regex Capture Groups
body: <p>I have a single string that is this kind of format:</p>
  
  <pre><code>"Mike H&lt;michael.haken@email1.com&gt;" michael.haken@email2.com "Mike H&lt;hakenmt@email1.com&gt;"
  </code></pre>
  
  <p>If I was writing a normal regex in JS, C#, etc, I'd do this</p>
  
  <pre><code>(?:"(.+?)"|'(.+?)'|(\S+))
  </code></pre>
  
  <p>And iterate the match groups to grab each string, ideally without the quotes. I ultimately want to add each value to an array, so in the example, I'd end up with 3 items in an array as follows:</p>
  
  <pre><code>Mike H&lt;michael.haken@email1.com&gt;
  michael.haken@email2.com 
  Mike H&lt;hakenmt@email1.com&gt;
  </code></pre>
  
  <p>I can't figure out how to replicate this functionality with <code>grep</code> or <code>sed</code> or bash regex's. I've tried some things like</p>
  
  <pre><code>echo "$email" | grep -oP "\"\K(.+?)(?=\")|'\K(.+?)(?=')|(\S+)"
  </code></pre>
  
  <p>The problem with this is that while it kind of mimics the functionality of capture groups, it doesn't really work with multiples, so I get captures like</p>
  
  <pre><code>"Mike
  H&lt;michael.haken@email1.com&gt;"
   michael.haken@email2.com 
  </code></pre>
  
  <p>If I remove the look ahead/behind logic, I at least get the 3 strings, but the first and last are still wrapped in quotes. In that approach, I pipe the output to <code>read</code> so I can individually add each string to the array, but I'm open to other options.</p>
  
  <p>EDIT: </p>
  
  <p>I think my input example may have been confusing, it's just a possible input. The real input could be double quoted, single quoted, or non-quoted (without spaces) strings in any order with any quantity. The Javascript/C# regex I provided is the real behavior I'm trying to achieve.</p>