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>You need to create separate groups:</p>

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

<p>To match these words. You don't even need <code>?</code> for this pattern.</p>

<p>This is a sed for multiple patterns:</p>

<pre><code>$ cat t1
Product: Toys, Books, Clothes, Radios ReqID:
Product: Toys, Books, Clothes, Radios ReqID:z
izProduct: Toys, Books, Clothes, Radios ReqID:

$ sed -e '/^Product:.*ReqID:$/ s/\(\w\+\)\(,\| \)/REPLACE\2/g' &lt; t1
Product: REPLACE, REPLACE, REPLACE, REPLACE ReqID:
Product: Toys, Books, Clothes, Radios ReqID:z
izProduct: Toys, Books, Clothes, Radios ReqID:
</code></pre>

<p>It looks for line starting with <code>Product:</code> and ending with <code>ReqID:</code>. For each line it matches <code>\(\w\+\)\(,\| \)</code></p>

python regex