Re: "negative" regexp



Abigail wrote:
_
Petr Vileta (stoupa@xxxxxxxxxxxxx) wrote on VCCLXV September MCMXCIII
in <URL:news:fnoj8a$1hin$1@xxxxxxxxxxxxxxx>:
;; I have problem to construct regexp, this is out of my brain ;-)
please help. ;;
;; I have string
;;
;; $string="<a href='big.gif'><img src='small.gif'></a><br><a
;; href='abc.htm'><b>click</b></a>";
;;
;; and I need to remove all html tags except <img ...>. The result
should be ;;
;; $string="<img src='small.gif'>click";
;;

Well, for your example,

s/<(?!img)[^>]*>//g

Thanks, this work OK.


The "right" way to do it is to use a proper HTML parser.

Get one from your nearest CPAN.

I'm tending to not use HTMP parsers because these construct a huge hashes and this is usually not needed for my purposes.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>

.



Relevant Pages

  • Re: different regexp result
    ... note that it does exactly what you said in english (however poor it ... print $string; ... Petr Vileta, Czech republic ...
    (comp.lang.perl.misc)
  • Re: different regexp result
    ... In Komodo IDE is Regexp Toolkit ... to test regular expressions. ... I have string and some stupid people are used to put space after aech single character to accentuate this words. ... Petr Vileta, Czech republic ...
    (comp.lang.perl.misc)
  • regexp for s///
    ... I need to write regexp for s/// subtitution but I can't to thinkup it. ... Now I want to create 2 variables called $myA and $myB and want to store values to both variables depend on found or not found A and B in $string. ... Petr Vileta, Czech republic ...
    (comp.lang.perl.misc)
  • Re: regexp for s///
    ... Petr Vileta wrote: ... Now I want to create 2 variables called $myA and $myB and want to store values to both variables depend on found or not found A and B in $string. ...
    (comp.lang.perl.misc)
  • Re: "negative" regexp
    ... Petr Vileta wrote on VCCLXV September MCMXCIII in ... ;; I have string ... ;; # remove all html tags ...
    (comp.lang.perl.misc)