I have the following data below where {n}
represents a placeholder.
{n}{n}A{n}{n}A{n}
{n}A{n}{n}{n}{n}A
{n}{n}A{n}A{n}{n}
{n}{n}{n}A{n}A{n}B
{n}A{n}{n}B{n}{n}
A{n}B{n}{n}{n}{n}
I would like to replace each instance of the placeholder between two A characters with for example the letter C
. I wrote the following regex for this and I'm using preg_replace
function.
$str = preg_replace('~(?<=A)(\{n\})*(?=A)~', 'C', $str);
The problem is that it replaces all instances between two A's with one C
. How could I fix my regex or the preg_replace
call to replace each individual instance of the placeholders with C
?
This should be my output.
{n}{n}ACCA{n}
{n}ACCCCA
{n}{n}ACA{n}{n}
{n}{n}{n}ACA{n}B
{n}A{n}{n}B{n}{n}
A{n}B{n}{n}{n}{n}
But currently it outputs this.
{n}{n}ACA{n}
{n}ACA
{n}{n}ACA{n}{n}
{n}{n}{n}ACA{n}B
{n}A{n}{n}B{n}{n}
A{n}B{n}{n}{n}{n}