Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi there Monks!
Can someone explain why this code does not match on my code? I have to use regular expression for this.
Thank you very much!!!

#!/perl/bin/perl use CGI qw(:header); use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; use strict; print header(); use warnings 'all'; my $directory = "/test"; my $new_file = "$directory/test.txt"; my $out_put; open(FH,'<',$new_file) || die $!; my @test = <FH>; foreach my $line (@test) { $line =~ /<!--\s+\d+nd movie -->\s*(.*?)\s*<!--\s+\/\d+nd movie -- +>/sgi; $out_put = $1; print $out_put; } close(FH);

Here is the test.txt file, I am trying to get whatever is in between tags - <!-- 1nd  --><!-- /1nd table --> and <!-- 2nd table --><!-- /2nd table -->:


test.txt
<!-- 3nd table --><table cellpadding="0" cellspacing="0" border="0"><t +r><td>Test Line no end of line.</td</tr></table><!-- /3nd table --> <!-- 1nd --> <table cellpadding="2" cellspacing="0" border="0"><tr><td><font color= +red>Test Line</font></td></tr></table> <!-- /1nd table --> <!-- 4nd table --><table cellpadding="0" cellspacing="0" border="1"><t +r><td><font color=navy>Test Line no end of line.</font></td></tr></ta +ble><!-- /4nd table --> <!-- 2nd table --> <table cellpadding="0" cellspacing="0" border="0"><tr><td>Test Line no + end of line.</td</tr></table> <!-- /2nd table -->


Thank you very much!!!

In reply to Regular Expression Matching Issue by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found