SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    List bbCode RegEx?

    I can't seem to make a regular regex for bbCode List parsing:

    e.g. when having with input:

    Code:
    [ list=1]
    [ *]List Item 1
    [ *]List Item 2
    [ *]List Item 3
    [ /list]
    (without spaces) (where [ list=1] creates an ordered list starting with 1)

    I want this output:
    Code:
    <ol class="numeric">
    	<li>List Item 1</li>
    	<li>List Item 2</li>
    	<li>List Item 3</li>
    </ol>
    Any help is appreciated. Thanks

  2. #2
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    preg_replace("/\[ list=1\](.+?)\[ /list\]/is"'<ol class="numeric">\1</ol>'$input); // For the whole list
    preg_replace("/\[ \*\](.+?)\n/"'<li>\1</li>'$input); // list 
    Its a start.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply, thats indeed a start.

    But let's say I am a user putting in this code

    Code:
    [ *] [ list=1]junk[ /list]
    it'll produce some invalid XHTML:

    Code:
    <li> <ol class="numeric">junk</ol></li>
    (the only valid element inside <ol> would typically be <li>, and not CDATA)

    So actually, I need a regex that's secure to this kind of input.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •