String replacement in R using stringr for long complicated string
<p>I have a long string from a SQL query that resembles the below:</p>

<pre><code>.*
[FOO] IN (1234, 2345, 3456, 4567, 5678, 6789, etc )
AND [BAR] IN (1,234,123,536,889,465)
.*
</code></pre>

<p>I basically want to replace the numbers in the <code>[FOO]</code> line without affecting anything else.</p>

<p>My desired output would look something like this:</p>

<pre><code>.*
[FOO] IN (9876,8765,7654)
AND [BAR] IN (1,234,123,536,889,465)
.*
</code></pre>

<p>I tried using the <code>regexp()</code> with <code>\\[FOO\\] IN \\(.*\\)</code> but that grabbed too much.</p>

<p>I also tried using <code>[0-9]{4}</code> but didn't know how to handle the commas since the last number doesn't have a comma at the end. </p>

<p>It should be noted that the length is varying, i.e. there can be different numbers of 4 digit codes in the foo line.</p>