SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular expression, BB parser

    Hi,
    I'm trying to build a BB parser, and have gotten as far as lists. I want the user to be able to write something like:

    [ulist]
    * item1
    * item2
    * item3
    [/ulist]
    and
    [olist]
    1. item1
    2. item2
    3. item3
    [/olist]

    The "*" I can deal with, it's basically just "~\s?\*([^\*]+)~", but my problem is with the ordered lists. If I write: "~\s?[0-9]+\.([^0-9\.]+)~", the matching stops if it finds a number, a dot, or both. I want it to stop only if it finds a number followed by a dot. How do I do that?

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should match them both:
    Code:
    /^\s*(?:\*|\d+\.)\s*(.*)/m

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but it didn't work. Tried to change your regexp but I couldn't make it work.

    EDIT:
    Sorry, it worked beautifully! I tested it with multiple items in the same line, but that shouldn't work. Thanks!


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
  •