CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
need regular expression for strip

 



grig
New User

Jul 29, 2011, 3:55 PM

Post #1 of 2 (4795 views)
need regular expression for strip Can't Post

I am new to perl and would like some help with regex for strip text from:


Quote
<span class="mtxt"> (live)</span>
&nbsp;<span class="spons_link_in_event_box"><a onclick="window.open('http://ad2.ip.ro/please/redirect/5405/1/1/10/?param=165779/169144_0_','_blank','scrollbars=yes,location=yes,menubar=yes,resizable=yes,toolbar=yes,width=860,height=580');return false;" href="http://ad2.ip.ro/please/redirect/5405/1/1/10/?param=165779/169144_0_"><font color="blue"><b>Pariaţi LIVE pe rezultate!</b></font></a></span>

<div style="display: none;">

<!-- Adserver zone (write): 62818, port_bet365_av_mero -->
<script type="text/javascript">
// <![CDATA[
if(!window.goA)document.write('<sc'+'ript src="http://imgs.adverticum.net/scripts/gwloader.js?ord='+Math.floor(Math.random()*1000000000)+'" type="text/javascript"><\/sc'+'ript>');
// ]]>
</script><script type="text/javascript">
// <![CDATA[
if(window.goA)goA.addZone(62818,{displayOptions:{bannerhome:'http://ad.adverticum.net'}});
// ]]>
</script><script charset="iso-8859-2" src="http://ad.adverticum.net/js.prm?zona=62818&amp;ord=c8Gh1Xu1Gp2Ob5Fi7Q&amp;re=http%3A%2F%2Fport.ro%2F"></script>
<noscript><a href="http://ad.adverticum.net/click.prm?zona=62818" target="_blank" title="Click here!"><img border="0" src="http://ad.adverticum.net/img.prm?zona=62818" alt="Advertisement" /></a></noscript>
</div>

<p class="desc_text">Dublin SuperCup</p>


I would like to strip all part of text starting with:
<div style="display: none;">
and end with:
</div>
Thanks.


BillKSmith
Veteran

Jul 29, 2011, 9:03 PM

Post #2 of 2 (4773 views)
Re: [grig] need regular expression for strip [In reply to] Can't Post

Although the Regex that you request is straightforward,

It is seldom a good idea to parse html with regular expressions.

Apparently minor changes to your data or requirements can break them completely.

It is safer to use any of several modules from CPAN.

If you are confident Wink that this will not happen:


Code
use strict; 
use warnings;
use Readonly;
my $html = <<'END_HTML';
<span class="mtxt"> (live)</span>
&nbsp;<span class="spons_link_in_event_box"><a onclick="window.open('http://ad2.ip.ro/please/redirect/5405/1/1/10/?param=165779/169144_0_','_blank','scrollbars=yes,location=yes,menubar=yes,resizable=yes,toolbar=yes,width=860,height=580');return false;" href="http://ad2.ip.ro/please/redirect/5405/1/1/10/?param=165779/169144_0_"><font color="blue"><b>Pariaţi LIVE pe rezultate!</b></font></a></span>

<div style="display: none;">

<!-- Adserver zone (write): 62818, port_bet365_av_mero -->
<script type="text/javascript">
// <![CDATA[
if(!window.goA)document.write('<sc'+'ript src="http://imgs.adverticum.net/scripts/gwloader.js?ord='+Math.floor(Math.random()*1000000000)+'" type="text/javascript"><\/sc'+'ript>');
// ]]>
</script><script type="text/javascript">
// <![CDATA[
if(window.goA)goA.addZone(62818,{displayOptions:{bannerhome:'http://ad.adverticum.net'}});
// ]]>
</script><script charset="iso-8859-2" src="http://ad.adverticum.net/js.prm?zona=62818&amp;ord=c8Gh1Xu1Gp2Ob5Fi7Q&amp;re=http%3A%2F%2Fport.ro%2F"></script>
<noscript><a href="http://ad.adverticm.net/click.prm?zona=62818" target="_blank" title="Click here!"><img border="0" src="http://ad.adverticum.net/img.prm?zona=62818" alt="Advertisement" /></a></noscript>
</div>

<p class="desc_text">Dublin SuperCup</p>
END_HTML
Readonly::Scalar my $div_tag => qr{<div.*>};
Readonly::Scalar my $div_text => qr{.*}ms;
Readonly::Scalar my $div_end_tag => qr{</div>};
Readonly::Scalar my $div => qr{$div_tag$div_text$div_end_tag};
$html =~ s/$div//g;
print $html;

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives