Welcome Guest, Not a member yet? Register   Sign In
Looking for regexp - [list] items
#1

[eluser]überfuzz[/eluser]
I'm looking for regular expressions to use in a bbcode parser. My current parser is working ok, but I'm not good enough with regexp to muster good expressions to handle
  • ; ordered, unordered, decimal, etc. It seems that I always miss out on something...

    I would be very thankful if anyone here could point me in the right direction, where as to look for them. Or if anyone has a regexp that can handle nestled
    • with or without different list-style.

      Thanks in advance.
#2

[eluser]WanWizard[/eluser]
In our old forum code we use
Code:
// old style lists
$text = preg_replace('#\[li\](.*?)\[/li\]#si', '<li style=\'margin-left:35px;\'>\1</li>', $text);
$text = preg_replace('#\[ul\](.*?)\[/ul\]#si', '<ul style=\'margin-left:-15px;\'>\1</ul>', $text);

// new style lists
$text = preg_replace('#\[list=1\](.*?)\[/list\]#si', '<ol>\1</ol>', $text);
$text = preg_replace('#\[list\](.*?)\[/list\]#si', '<ul>\1</ul>', $text);
$text = preg_replace('#\r\n\[\*\]#si', '<li>', $text);
#3

[eluser]überfuzz[/eluser]
Thats about what I can handle myself. I'm running into trouble if I'm trying to extend your regexp:es. First of all I can't extend them to handle upper-roman nestled with lower roman. Furthermore, I can't get the HTML output to validate. Shouldn't the nestled <ol>list items</ol> sit inside the <li>here</li> tags?

Example of how I would like to extend it, not working but still...
Code:
$string = preg_replace('#\[list=a\](.*?)\[/list\]#si', '<ol style="list-style-type:lower-alpha;">\1</ol>', $string);
    $string = preg_replace('#\[list=A\](.*?)\[/list\]#si', '<ol style="list-style-type:upper-alpha;">\1</ol>', $string);
    $string = preg_replace('#\[list=I\](.*?)\[/list\]#si', '<ol style="list-style-type:upper-roman;">\1</ol>', $string);
    $string = preg_replace('#\[list=i\](.*?)\[/list\]#si', '<ol style="list-style-type:lower-roman;">\1</ol>', $string);
#4

[eluser]WanWizard[/eluser]
Issue with the upper/lower is probably that you use a case-insensitive regex, so list=I equals list=i, which makes them all upper.
#5

[eluser]überfuzz[/eluser]
[quote author="WanWizard" date="1273578687"]Issue with the upper/lower is probably that you use a case-insensitive regex, so list=I equals list=i, which makes them all upper.[/quote]

Wops, I see that I missed out on posting an example of the output. The upper/lower roman chars were mixed, seemingly in a random matter, if I nestle the lists.




Theme © iAndrew 2016 - Forum software by © MyBB