REGEX (Regular Expression) to Remove/Strip HTML Tags in PERL

REGEX (Regular Expression) to Remove or Strip HTML Tags in PERL

REGEX (Regular Expression) to Remove/Strip HTML Tags in PERL

The following regular expression can be used in Perl progamming language to remove/strip HTML tags in given string.

Regular Expression:

s/<(?:[^>'”]*|([‘”]).*?\1)*>//ig

 

Example:

my $data ='<script>TEST</script> <img src="img.jpg">';

$data =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//ig;

print $data;

Output:

TEST

[ YOU MAY ALSO LIKE ]

Leave a Reply