PHP Regex for replace alternative : <p>I have a requirement for which I am trying to find a regex pattern to replace the code. I understand that I can get normal regular expression for finding and replacing the text however reqirement is to find and replace the instance alternatively.</p>

<p>For example, </p>

<pre><code>{code}
UPDATE tenants SET end_user_uuid = '32392464c8a19a15dd8dc982ae3d574b' WHERE end_user_uuid = '9e194bfeace6c2d17cc71cc15e84f93a' AND instance_id = '265358' AND domain = 'automobieljansen';
{code}

Rollback: 

{code}
UPDATE tenants SET end_user_uuid = '9e194bfeace6c2d17cc71cc15e84f93a' WHERE end_user_uuid = '32392464c8a19a15dd8dc982ae3d574b' AND instance_id = '265358' AND domain = 'automobieljansen';
{code}
</code></pre>

<p>This is the original text. I need to replace the first instance of the <code>{code}</code> to <code>&lt;pre&gt;</code> and the second instance of the <code>{code}</code> to <code>&lt;/pre&gt;</code></p>

<p>Expected result</p>

<pre><code>&lt;pre&gt;
UPDATE tenants SET end_user_uuid = '32392464c8a19a15dd8dc982ae3d574b' WHERE end_user_uuid = '9e194bfeace6c2d17cc71cc15e84f93a' AND instance_id = '265358' AND domain = 'automobieljansen';
&lt;/pre&gt;

Rollback: 

&lt;pre&gt;
UPDATE tenants SET end_user_uuid = '9e194bfeace6c2d17cc71cc15e84f93a' WHERE end_user_uuid = '32392464c8a19a15dd8dc982ae3d574b' AND instance_id = '265358' AND domain = 'automobieljansen';
&lt;/pre&gt;
</code></pre>

<p>Any help on how to do this easily? </p>
