in reply to Why doesn't non-greediness work?
All of the other folks have pointed out the right way to match just one HTML tag. I would recommend that you search "defensively" to avoid breaking if the HTML changes slightly, to help future programmers see what you're trying to do, and to make it easier to add obvious new extensions.
One, show that you're expecting the magic "Smiley" string in the ALT parameter.
Two, allow for other things to follow the magic string.
Three, search with the /i case insensitivity modifier.
Four, optionally, make the pattern a little more readable with the /x modifier and some whitespace.
Five, optionally, make a hash of possible magic strings and your desired emoticon replacements, to make new extensions very easy.
Six, optionally, comment on the intent of complex patterns with a very brief example.
my %emoticons = ( smiley => ':)', wink => ';)', ); # example: <img alt="smiley"> becomes :) foreach my $e (keys %emoticons) { $body =~ s{ \< img [^>]*? alt = "$e" [^>]*? \> } {$emoticons{$e}}igex; }
--
[ e d @ h a l l e y . c c ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Why doens't non-greediness work?
by halley (Prior) on May 10, 2003 at 15:00 UTC |