Best unofficial Apache Server developers community |
|
Heya, you often helped me, guys, so I hope you may do it again :] I have a string, which contains HTML Data (which doesnt necessarily have
tags, but it can have then sometimes), and I want to replace a string. Actually, Im doing it like "replace the first find of
with
", but that doesnt work when a table is done, because the "newdiv" needs to be outside the table. Is there any way of telling PERL to replace only after a certain tag (in my case it would be
) has been found before the search? Thanks!
posted via StackOverflow
|
|
 
|
why don't you go through the file line by line, counting all the start/end tags of a table. and if the sum is zero (all starting table tags are closed with an end tag) you do the matching/replacing.. |
|
 
|
Parsing HTML with regexes is generally a bad idea. It's especially bad in the generalized case of handling arbitrary HTML. However, it typically gets less and less bad the more you can restrict the inputs you are dealing with. Have you tried using HTML::TreeBuilder or HTML::Parser to parse your HTML? This untested code should do what you want--as far as I can tell from your description, please post sample data and desired results where possible.
|