Finding global matches inside a pattern
<p>If I have a pattern like this: (<a href="https://regex101.com/r/cR0aG8/12" rel="nofollow">https://regex101.com/r/cR0aG8/12</a>)</p>

<pre><code>Product:.*?(.*?),.*?ReqID:
</code></pre>

<p>I assume(d) that</p>

<pre><code>Product.*?(.*?),.*?ReqID:
</code></pre>

<p>would find <code>Toys</code>, <code>Books</code>, <code>Clothes</code> individually with G(lobal) on since to my (somewhat newbie) eye it is looking for ANY match that has <code>Product:</code> and any string ending in a comma before it and any string ending in <code>ReqID:</code> after it.</p>

<p>But as you can see by the regeg101 global-on gets the exact same result as global-off; the very first ,. Is there a way to structure this so the regex says just that (any string preceded by <code>Product:</code> and a <code>,</code> and followed by a <code>ReqID</code>? </p>

<p>Essentially I need to gather all values before or after a <code>,</code> that are bordered by the start/end pattern.</p>

<p>If you are using PCRE engine (like your demo is made on it) or any of .NET, Java, Ruby or Perl regex flavors then use start match from end of previous one token <code>\G</code>:</p>

<pre><code>(?:Product:|(?!\A)\G)(\s+\w+),
</code></pre>

<p><a href="https://regex101.com/r/hG6gP8/3" rel="nofollow">Live demo</a></p>

<h2>Update</h2>

<p>Based on new requirements:</p>

<pre><code>(?:Product:|(?!\A)\G)\s*(\w+)(?:,| \w+:)
</code></pre>

<p><a href="https://regex101.com/r/hG6gP8/4" rel="nofollow">Live demo</a></p>

python regex