Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2016-10-27 10:37 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (358 votes). Check out past polls.