logie17 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I have a situation where I have a string of data which contains essentially encoded html text, and could really be any size. I then take that string and substring it. Once that is done I use a regular expression to search and replace the html encoded tags. I then use another regular expression to attempt to chop off any unclosed html encoding that might be left at the end of the string. To make a long story short my code appears to be working, however I'm sure there is a way to refactor my regular expressions perhaps into a single statement. Any help would be highly appreciated.
Example Code
I have a situation where I have a string of data which contains essentially encoded html text, and could really be any size. I then take that string and substring it. Once that is done I use a regular expression to search and replace the html encoded tags. I then use another regular expression to attempt to chop off any unclosed html encoding that might be left at the end of the string. To make a long story short my code appears to be working, however I'm sure there is a way to refactor my regular expressions perhaps into a single statement. Any help would be highly appreciated.
Example Code
Is there any way to combine the two regex examples? Thanks again.$string = substr($incoming, 0, 177); $string =~ s/\<\;?[-.a-zA-Z0-9]*.*?\>\;//gs; #This does a great j +ob axing anything basically that starts with a < and ends with a > $string =~ s/\<\;?[-.a-zA-Z0-9]*.*$//gs; #Due to my substring there + is sometimes an open bracket such as <img src...chomp
s;;5776?12321=10609$d=9409:12100$xx;;s;(\d*);push @_,$1;eg;map{print chr(sqrt($_))."\n"} @_;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Refactoring Regular Expressions
by chromatic (Archbishop) on Apr 25, 2007 at 06:14 UTC | |
Re: Refactoring Regular Expressions - HTML encoded text
by varian (Chaplain) on Apr 25, 2007 at 06:51 UTC | |
Re: Refactoring Regular Expressions
by Herkum (Parson) on Apr 25, 2007 at 11:44 UTC | |
Re: Refactoring Regular Expressions
by graff (Chancellor) on Apr 26, 2007 at 01:22 UTC |
Back to
Seekers of Perl Wisdom