Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Regular Expression tricky newline problem

by tirwhan (Abbot)
on Jan 02, 2006 at 22:13 UTC ( #520465=note: print w/ replies, xml ) Need Help??


in reply to Regular Expression tricky newline problem

Use a non-greedy match:

#!/usr/bin/perl use strict; use warnings; local $/=undef; my $contents=<DATA>; my ($thirdline) = $contents =~ m/Line3 : (.*?)\n/s; print $thirdline."\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
Output:
Dit is de derde regel
Or you could match against a negated character class:
my ($thirdline) = $contents =~ m/Line3 : ([^\n]+)/s;

A computer is a state machine. Threads are for people who can't program state machines. -- Alan Cox


Comment on Re: Regular Expression tricky newline problem
Select or Download Code
Reaped: Re^2: Regular Expression tricky newline problem
by NodeReaper (Curate) on Jan 03, 2006 at 03:58 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-12-25 05:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls