I'm trying to delete a ul tag and nested tags inside that ul.
<ul class="related">
<li><a href="/related-1.html" target="_blank">Related article</a></li>
<li><a href="/related-2.html" target="_blank">Related article 2</a></li>
</ul>
I just deleted the nested li inside the ul using this (I'm using php for this thing, so I pulled content from a db as $content)
$content = $rq['content']; //here is the <ul class="related">... code
$content1 = preg_replace('~<ul[^>]*>\K(?:(?!<ul).)*(?=</ul>)~Uis', '', $content); //it works here
So far I get the next string in $content1
<ul class="related"></ul>
So how do I delete this piece of remaining code using regex? I tried the similar pattern but did not get the results I am wanting.
$finalcontent = preg_replace('~<ul[^>]*>\K.*(?=</ul>)~Uis', '', $content1);
` and its contents? Just use `~
– ctwheels Feb 07 '18 at 19:34]*>.*
~iUs`. But as @RyanWilson said, regex isn't the best option for this. It's unclear what the expected output is.and delete it or substitute it with a blank ''. im sorry for my explanation :( – Jaciel Lv Feb 07 '18 at 19:51