1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regex help wanted

Discussion in 'XenForo Questions and Support' started by Brogan, Jan 24, 2011.

  1. Brogan

    Brogan 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.

    Code:
    [media=youtube:3n7eycix]i_eQGsbHhDo[/media:3n7eycix]
    [media=youtube:3cyuajl6]owodGwwjv_o[/media:3cyuajl6]
    
    
    [spoiler=question:3df2kebg]Answer[/spoiler:3df2kebg]
    [spoiler=question:9cv8skji]Answer[/spoiler:9cv8skji]
    Table code is just as bad:
    Code:
    [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.
     
  2. Jaxel

    Jaxel Well-Known Member

    Code:
    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);
     
    Brogan likes this.
  3. Brogan

    Brogan 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.
     
  4. Jaxel

    Jaxel Well-Known Member

    http://www.regexbuddy.com/
     
  5. Brogan

    Brogan 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
     
  6. Floris

    Floris Guest

    EQnoble likes this.
  7. Floris

    Floris Guest

    Btw, you using the post regex thing by Kier?
     
  8. Brogan

    Brogan XenForo Moderator Staff Member

    Yes, what a great tool it is :)

    That and a few SQL queries to finish off has sorted everything.
     
  9. EQnoble

    EQnoble Well-Known Member

    What is this tool you speak of? I need help with regex BAD in general.
     
  10. Brogan

    Brogan XenForo Moderator Staff Member

  11. Floris

    Floris Guest

    Sweet, glad to hear you're moving forward with the Import. :)
     
    EQnoble likes this.
  12. EQnoble

    EQnoble Well-Known Member

Share This Page