Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Regular Expression tricky newline problem

by bobf (Monsignor)
on Jan 02, 2006 at 22:16 UTC ( #520467=note: print w/ replies, xml ) Need Help??


in reply to Regular Expression tricky newline problem

Use '?' to get a nongreedy match up to the first newline:

$data =~ m/Line3 : (.*?)\n/s;

You can also use a greedy match with a negated character class:

$data =~ m/Line3 : ([^\n]*)/s;

My test code follows:

use warnings; use strict; my $data = join( '', <DATA> ); print "[$data]\n\n"; $data =~ m/Line3 : (.*?)\n/s or die; print "match: [$1]\n"; $data =~ m/Line3 : ([^\n]*)/s or die; print "match: [$1]\n"; __DATA__ Line1 : Dit is de eerste regel Line2 : Dit is de tweede regel Line3 : Dit is de derde regel Line4 : Dit is de vierde regel


Comment on Re: Regular Expression tricky newline problem
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://520467]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2014-08-23 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls