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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-06-28 13:01 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (637 votes). Check out past polls.