Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: getting and printing form values etc from html stripping out all elseby ww (Archbishop) |
on Feb 25, 2010 at 02:13 UTC ( [id://825228]=note: print w/replies, xml ) | Need Help?? |
For your first requirement, a regex is probably safe and effective, since (unless I'm having a Sr. moment) the html 4.x standard does not allow an image tag with a literal ">" inside the tag. One way to approach the job, therefore, is to extend your regex with less-greedy (aka "minimally greedy") matching and a lookahead. Here's a sketch, minus file-handling, CGI, etc:
Output:
BUT take the advice from pemungkah above: Use a parser! Trying to deal with all the possible unwanted tags in a form with regexen is going to get you deeper and deeper into complexities. And if you're planning to read user input from a form, for heaven's sake, read about untainting. You really don't want to let the fumble-fingered or malicious run around loose in your playground.
In Section
Seekers of Perl Wisdom
|
|