Regex help wanted


XenForo moderator
Staff member
I did a test import of my phpBB forum to vB as the first step to converting to XenForo.

Unfortunately, as expected, all of my custom BB Code is a mess.
Due to the way phpBB appends a different hex string onto each BB Code/post combination, it's not a simple matter of doing a simple SQL REPLACE query.
Here's an example of what some basic youtube and spoiler code looks like.


Table code is just as bad:
[tablebox:2l8tutbq][table:2l8tutbq][tr:2l8tutbq][th:2l8tutbq]Grand Prix[/th:2l8tutbq][th:2l8tutbq]Winning Driver[/th:2l8tutbq][th:2l8tutbq]Winning Constructor[/th:2l8tutbq][th:2l8tutbq]Time[/th:2l8tutbq][th:2l8tutbq]Pole Position[/th:2l8tutbq][th:2l8tutbq]Time[/th:2l8tutbq][th:2l8tutbq]Fastest Lap[/th:2l8tutbq][th:2l8tutbq]Time[/th:2l8tutbq][/tr:2l8tutbq][tr1:2l8tutbq][td1:2l8tutbq]Bahrain[/td1:2l8tutbq][td1:2l8tutbq]
Notice the hex strings are different in each case.
Therefore it looks like my only solution is to use regex, which is voodoo as far as I'm concerned :D

So if anyone can help with constructing some regex to tidy up my BB Code, I'd be eternally grateful.


Well-known member
preg_replace('#\[media=(\w+).*?\](.*?)\[/media.*?\]#i', '[media=$1]$2[/media]', $message);
preg_replace('#\[spoiler=(\w+).*?\](.*?)\[/spoiler.*?\]#i', '[spoiler=$1]$2[/spoiler]', $message);

preg_replace('#\[table.*?\](.*?)\[/table.*?\]#i', '[table]$1[/table]', $message);
preg_replace('#\[tr.*?\](.*?)\[/tr.*?\]#i', '[tr]$1[/tr]', $message);
preg_replace('#\[td.*?\](.*?)\[/td.*?\]#i', '[td]$1[/td]', $message);
preg_replace('#\[th.*?\](.*?)\[/th.*?\]#i', '[th]$1[/th]', $message);
preg_replace('#\[tablebox.*?\](.*?)\[/tablebox.*?\]#i', '[tablebox]$1[/tablebox]', $message);


XenForo moderator
Staff member
Many thanks Jaxel, that is very much appreciated.

I will try and decipher those to see how they work as I have quite a lot of custom BB Code so will need to run a few more queries.


XenForo moderator
Staff member
Just wanted to add that with a combination of Jaxel, Mike and Kier, I have managed to solve all of the problems related to custom BB Code.

Now my post content actually looks like content instead of some weird cipher.

XenForo here I come :D