Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How to convert character '<' to '<' and '>' to > for all the characters which is not present in the array#!/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) ? "& +lt;$2>" : "<"/eg; print $line; } __DATA__ <helloe>How r u <a> www.google.com</a> <hi>How r u </hi><et,-2><><br/>
<helloe>How r u <a> www.google.com</a> <hi>How r u </hi><et,-2><><br/>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: convert characters
by Utilitarian (Vicar) on Aug 27, 2009 at 12:24 UTC | |
by Anonymous Monk on Aug 27, 2009 at 12:37 UTC | |
by Utilitarian (Vicar) on Aug 27, 2009 at 12:39 UTC | |
by Anonymous Monk on Aug 27, 2009 at 16:26 UTC | |
by Utilitarian (Vicar) on Aug 27, 2009 at 18:17 UTC |