SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: regex - nesting

  1. #1
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regex - nesting

    Hi all,

    I've been looking around for an BBCode WYSIWYG, preferably something similar to what Sitepoint has.

    On my travels, I found FCKEditor which has a BBCode plugin that allows you to convert all the html into BBCode, but it only supports the simple Bold, Italic, Underline and Link.

    My client wants more out of it, so it looks like I have to write some regex strings to parse the HTML into BBCode.

    I've hit a snag where nested tags are cancelling each other out.

    Can anyone point out a way to match and handle nested tags via regex?

    This is the html i'm dealing with at the moment:

    Code xhtml:
    <span style="background-color: red;">Some <span style="text-align: right;">content</span></span>

    This is what I have at the moment,


    <span.*?style="background-color:[ ](.*?);">(.*?)</span>


    but it matches

    Code xhtml:
    <span style="background-color: red;">Some <span style="text-align: right;">content</span>

    Any idea?

    Cheers


  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't do that with regular expressions. Regex'es only match patterns, they have no context. Sorry.

    For parsing HTML, you would probably be best off using a ready-made parser, such as DOM.

  3. #3
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ? I need to convert (x)html to BBCode and back again.



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
  •