Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Multiline regex

by haoess (Curate)
on Oct 27, 2006 at 18:36 UTC ( #580989=note: print w/ replies, xml ) Need Help??


in reply to Multiline regex

If you want to do your matching about the whole string (containing multiple lines), then you want /s (also let the dot meta character match line breaks).

my ($body) = $line =~ /^body: \n (.*) \n attachment/xsi;

Or you are matching line by line, then you should have a look at the flip-flop operator in perlop.

# this is from perlop while (<>) { $in_header = 1 .. /^$/; $in_body = /^$/ .. eof; if ($in_header) { # ... } else { # in body # ... } }

--Frank


Comment on Re: Multiline regex
Select or Download Code
Re^2: Multiline regex
by chargrill (Parson) on Oct 27, 2006 at 18:56 UTC

    Also see Flipin good, or a total flop? for a good discussion of the flip-flop operator by Grandfather.



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2015-07-05 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls