Jump to content

Regex wizards - matching same number of opening and closing tags


frizi

Recommended Posts

Hi

 

It would  be great if you could help me with my problem. I would like to use a regex expression (or a php script) that would select one complex tag. The complexity at this is that the tag could contain the same tag inside (at menu content for example - ul li ul).

 

Therefor I need a special code that would search so many closing tags as many opening tags for matching the following first UL:

 

<ul> <li> first </li>

<li> <ul>

<li> second </li>

<li> <ul> third </ul> </li> </ul> </li>

<li> <ul> <li> fourth </li> </ul> </li>

<li> end of selection </li>

</ul>

<ul> this should be not selected </ul>

 

I need to search so many opening tags as closing tags from the first tag (ul) until next different tag.

It was told me that I should use Dom document. This is not possible because I'm working with transitional style html style and I need just the first level (main) tags.

 

Thank you in forward.

You should be using the DOM. If you're having trouble doing that, please ask questions.

 

Any regex solution will be far more complicated and difficult to maintain and understand in the future (or even, now).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.