Code:#!/usr/bin/perl while($line = <DATA>){ @valid_entities= ('<a>','<abbr>','<acronym>','<br>'); my %htmlenties = map { $_ =>1 } @valid_entities; #$line =~ s/(<\w*?>(?![^<\w*?>]*<\/\w*?>))/$1/g; #$line =~ s/<\w*>(?![^<\/\w*>]*>)/</g; $line =~ s/(<(\w*?)>)/exists $htmlenties{$1} ? $1 : defined ($2) ? "<$2>" : "<"/eg; print $line; } __DATA__ <helloe>How r u <a> www.google.com</a> <hi>How r u </hi><et,-2><><br/>
How to convert character '<' to '<'and '>' to > for all the characters which is not present in the array and only if it doesnot have a closing end tag.In the above example,
the output should look like
Code:<helloe>How r u <a> www.google.com</a> <hi>How r u </hi><et,-2><><br/>





Bookmarks