Jump to content

Tricky Regex, challange the impossible


frizi

Recommended Posts

Hi!

 

I would like to ask if someone could help me out with the issue which I'm confronting with.

 

My goal is to cut the whole tag that might contain the ending tag that of the root tag. For example:

 

<p id="test" class="932">

line1 <b> test of B</b>

<p> ignore this paragraph</p>

some text</p>

 

// and don't finish at "this paragraph</p>"

 

<ul id="test" class="932"><li>line1</li>

<li><ul id="test2" class="done"><li> subline 1</li>

<li> subline 2 </li>

</ul>

<li> line2</li>

</ul>

 

// and don't finish at "e 2 </li></ul>"

 

if there is a way how to solve this, please let me know. There could be different tags with different attributes. Important is to cut out the root tag. I'm stuck in that problem and I would need a advice.

 

Thank you!

Link to comment
Share on other sites

It is certainly not impossible, though if you are struggling now then perhaps it best to offer up an alternative or two instead of what will inevitably be a confusing regex solution.

 

Personally, if at all convenient, I would use the DOM extension to completely bypass the issue you're having.  You could simply target the element with the id of test and magically have the entire thing very easily.

 

If you still want someone to rise to the 'challange' then of course, I'm sure some kind fellow will be along to accommodate such a request.

Link to comment
Share on other sites

I was thinking in similar way. I think it would be better to make a function that is checking if the first selected tag contains the root tag and if yes, take the second, or as many such tags are enclosed, closing tag.

I was also thinking to use simplexml functions to work with those tags.

 

Anyway, thanks for your help!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.