On Tue, Sep 17, 2002 at 12:00:45PM +0200, allan juul wrote: > hi > > we need to replace tags like: > > <img src="Some/Path" anthing="anything"> > > to: > > <img src="Some/Path" anthing="anything" /> > > > it seems so simple but i am on the verge of giving up understanding the > negative lookahead logic. > > this is how far i have come (obviously not working) > > my $src = qq(<img src="Some/Path" anthing="anything">); > $src =~ s/(<img(?![^>]+\/))>/$1\/>/ig; > print $src
The negative lookahead part is fine, except that it doesn't actually match the rest of the tag, so your replacement puts the /> in the middle of the tag and leaves the rest intact. I think this will work pretty well: $src =~ s,(<img[^>]+)(?<!/)>,$1 />,ig; Ronald