MyBB Community Forums

Full Version: Find / Replace template help (regular expressions)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone, 

upon developing a plugin for my member_profile I've run into a problem with find_replace_templatesets in the install bit. The problem is that I can't  find the correct code for the replacement as I already know that I will have two more plugins (number 1 and 3 down below) that might interfere here. I want to find a solution where it does not matter in which order the 3 plugins are installed and I want them to stay separated.

In the end it all will look something like this:
{$signature}
{$plugin1}
</td>
</tr>
</table>
{$plugin2} <- That's the one I'm talking about
{$plugin3}
{$modoptions}

So to place the code for plugin 2 I cannot say "Put something behind the signature table bit" because if plugin1 is already installed it will not work. And I can not say "Put something before modoptions" because Plugin3 might interfere. 

I've tried to do something like this:
find_replace_templatesets('member_profile', '#'.preg_quote("{$signature}.*</table>").'#i', '{\$signature}.*</table>\n {$plugin2}'); 

The preg_quote idea is from here.
However this does not work at all. (Maybe just because I'm not really good at regular expressions :/ )

Do you have any suggestions?
Thanks in advance!

Senya
'{\$signature}.*</table>\n {$plugin2}'
That's not how replacements work in PHP (you should use $ + number, check documentation: http://php.net/manual/en/function.preg-replace.php). I'm not fully sure what you meant, but I guess you wanted a capture group in the regex, so .* enclosed in parentheses?

EDIT: also, not sure why you escaped $ in {\$signature} (but not in {$plugin2}, which is correct)