title: How to extract multiple non-greedy regex-matching parts from a line?
body: <p>If I have a file like this:  </p>
  
  <pre><code>abc defghaijkb,mnaobpqa
  pbqaaa
  qrs - a .. b ...
  cde
  </code></pre>
  
  <p>How to extract all the parts which start with <code>a</code> and end with <code>b</code> (I choose these chars to simplify the example, they may be replaced with some more complex regex)? This is a desired output:  </p>
  
  <pre><code>ab
  aijkb
  aob
  a .. b
  </code></pre>
  
  <p>(Putting each item at a separate line). Since there's no non-greedy matching (<code>.*?</code>) in (g)awk, I cannot find how to solve this (eg. using <code>split</code>).  </p>
  
  <p>Note 1: there will be no need to use multiline matching - that is, no newlines allowed between <code>regex1</code> and <code>regex2</code>.  </p>
  
  <p>Note 2: I don’t want to use <code>sed</code>, I want to know if this can be done with awk, or bash, or some another command-line tool that processes an input file line-by-line...  AWK seems to be a nice solution, but... if only it supported non-greedy <code>.*?</code></p>
  
  <p>Note 3: I cannot use <code>grep</code> because I am always getting <code>memory exhausted</code> error when I deal with huge files.</p>
  
  <p>Note 4. Here is an example of a more complex <code>regex1</code> and <code>regex2</code>. What if they can contain non-greedy <code>.*?</code> ? Eg. <code>&lt;a&gt;.*?&lt;b&gt;.*?&lt;/b&gt;.*?&lt;/a&gt;</code>. </p>
  
  <p>Update. More complex example:  </p>
  
  <pre><code>[a]text1[a]text000[b]text2[/b]text11[/a]c defgh[a]text3[b]text33[/b]text333[/a]...[/a],mnaobpqa
  ...[b]aa[/b]bb[/a],,,
  qa - [a][b][/b][/a] aabbcc ...
  cde
  </code></pre>
  
  <p>Desired output:  </p>
  
  <pre><code>[a]text000[b]text2[/b]text11[/a]
  [a]text3[b]text33[/b]text333[/a]
  [a][b][/b][/a]
  </code></pre>