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

Re: question on multi line pattern matching for html formatting

by EvanCarroll (Chaplain)
on May 17, 2009 at 09:51 UTC ( #764495=note: print w/ replies, xml ) Need Help??


in reply to question on multi line pattern matching for html formatting

The first reply addresses doing this right way, I'll go ahead and show you how to do it the wrong way, using line matching like you tried. We'll achieve the same effect though.

#!/usr/bin/perl -l use strict; use warnings; my $file; { local $/ = undef; $file = scalar <DATA>; } ## Find me two newlines or be the start of the file ## Followed by any amount of newlines ## Followed by one or more characters (our capture, your paragraph) ## Followed by any amount of newlines ## Followed by any two newlines or the end of the file ## Flags: treat the file as one line, continue search for more paragra +phs (/g in list context) while ( $file =~ m/ (?>\n{2}|\A) \n* (.+?) \n* (?=\n{2}|\z)/sxg ) { print "<p>$1</p>"; } __DATA__ Paragraph one is this Paragraph two is this Paragraph three is this Paragraph three and this But stops here and doesn't get the rest of the newlines


Evan Carroll
The most respected person in the whole perl community.
www.EvanCarroll.com


Comment on Re: question on multi line pattern matching for html formatting
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-12-22 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (110 votes), past polls