Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

BBCode conversion

  •  08-23-2008, 8:30 PM

    BBCode conversion

    Hi, I asking for help in my PHP code optimization. I try to rewrite my old/slow BBCode conversion function to use regex. The allowed BBCodes are

    [ b]text[ /b]
    [ i]text[ /i]
    [ url]domain.com[ /url] or [ url]domain.com|domainname[ /url]
    [ img]filename.ext[ /img] or [ img]filename.ext|description[ /img]

    It is possible to construct regex with the following conditions?

    [ b] - inside only [ i] and [ url] BBCode allowed, newline NOT allowed
    [ i] - as [ b]
    [ url] - inside NO BBCode allowed, newline NOT allowed
    [ img] - as [ url]

    (I try to make difference between two [ url] (or [ img]) syntax with '/\[url\](.+?)\[\/url\]/is' and '/\[url\](.+?)\|(.+?)\[\/url\]/is' patterns, but it generates malfunction.)

    Thanks for help in advance 

View Complete Thread