$str='\add[sometext]{\begin{equation}\label{eqn:3}
f_{1} =
\begin{cases}}
\beta_{1} + \beta_{2}f_{2} & f_{2}\leq \gamma\\
\beta_{1} + \beta_{2}\gamma + \beta_{4}(f_{2}-\gamma) & f_{2} >\gamma
\end{cases}sdsdssd,
\end{equation}}
 it may have some extra code here with {}
 \end{equation}}'
I need to extract the string between \add[sometext]{ and }(i.e.till \add tag end curly braces)The string between \add[sometext]{ and } may varies so I can't specify these string in regex pattern I should only consider starting and ending curly braces of \add[sometext]
Expected output:
\begin{equation}\label{eqn:3}
    f_{1} =
    \begin{cases}
    \beta_{1} + \beta_{2}f_{2} & f_{2}\leq \gamma\\
    \beta_{1} + \beta_{2}\gamma + \beta_{4}(f_{2}-\gamma) & f_{2} >\gamma
    \end{cases}sdsdssd,
    \end{equation}
I tried:
$str=preg_replace('/\\\\add\s*\[\s*\w*\]\s*{(.*?)}/s,$1,$match)
I don't know how to get related curly braces (i.e.\add tag start { till end })
 
    

 
    