Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Regular Expression tricky newline problem

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


in reply to Regular Expression tricky newline problem

Greedy matching works as long as you're not using the /s modifier:

use strict; my $string = join '', <DATA>; if($string =~ /^Line3 : (.*)/m) { print "$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
The /m modifier is necessary to have the ^ anchor match the beginning of any line in a multi-line string. The greedy .* will then match anything until the end of that line.

Had you used the /s modifier, the greedy .* would have matched newlines as well and therefore gobbled up everything until the end of the multi-line string.


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:57 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-11-28 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (197 votes), past polls