Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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

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 studying the Monastery: (8)
As of 2016-09-28 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (541 votes). Check out past polls.