Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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]
erix imagines trump-nominees poring over the wikipedia-page of their ministery's subject

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2017-01-20 00:43 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (173 votes). Check out past polls.