Results 1 to 3 of 3

Thread: Regex question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2004
    Posts
    751

    Regex question

    I have recently been presented with a problem.
    Lets take the list
    [ul=list1,list2,list3]
    I am trying to figure out how to extract that list and turn it into a HTML ul.
    Though, I don't think regex will be able to do something like this, I could be wrong.
    Anyone with an ideas of how I could do this?

    Edit: This list will be embedded in a text file with lots of other text so the issue isn't how I can parse just that list by itself, but how can I parse that list when its mixed in with other text.
    My Projects: [ Instant Messagener Client/Server ] [ VBPictochat ]

    My Sites:
    [ Datanethost ]
    [ Helpdesk ]

    Remember if my post was helpful then Rate This Post.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Regex question

    Yes, regular expressions should be able to help you here. You know that [ul= is a must-have in order to identify it as an unordered list.

    This, for example, should be a good starting point.

    \[ul=[a-zA-Z0-9,]*\]

    I assume you then know how to parse the list to get the list items...

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Regex question

    You could use the 'e' modifier to call a function which formats the list items.

    PHP Code:
    function listformat($listitems) { /* ... */ };
    preg_replace('#\[ul=([^\],],?)+\]#es'"'<ul>'.listformat('\\1').'</ul>'"$subject); 
    Something along those lines.

Posting Permissions

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



Click Here to Expand Forum to Full Width