Chris Schults wrote: > I have a text string, with some HTML code, that I truncate (using substr). > In some instances, I truncate off some HTML close tags. > > In the case of anchor tags, I do this (please tell me if there is a more > elegant ay to do this!): > > if ($text =~ /\<a href/ && $text !~ /\<\/a\>/) {$text .= '</a>';} > > But I realized that this doesn't work if there is more than one link, like > so: > > Here is <a href="#">some text</a> that got <a href="#">truncated > > Any suggestions? > > Chris
This is why many here continually advocate the use of HTML parsing modules for this type of work. The more elegant way to do this would be to use an HTML parser and drop the regexes completely. There are a number available from CPAN, and I have found working with HTML::TokeParser::Simple to be, well, simple. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>