This is the correct regex
$rainbowtext = "[rainbow]text here[/rainbow]";
$rainbowtext = preg_replace("#\\[rainbow\\](.*?)\\[/rainbow\\]#","\\\\1",$rainbowtext);
You need to test the result to see if it matched if not rainbow() it.
function rainbow( $S )
{
return "rainbow=$S";
}
$rainbowtext = "[rainbow]text here[/rainbow]";
if( $rainbowtext != ($r=preg_replace("#\\[rainbow\\](.*?)\\[/rainbow\\]#","\\\\1",$rainbowtext)) )
{
$rainbowtext = rainbow( $r );
}
echo $rainbowtext;
HalfaBee