Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
There's more than one way to do things
 
PerlMonks  

Re: Regexp help, multiple lines

by CombatSquirrel (Hermit)
on Aug 15, 2004 at 18:02 UTC ( [id://383150]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Regexp help, multiple lines

In this case you might want to use \d in your RegEx to match any digit. You probably also want to make that star non-greedy (add a ? to it).
A common idiom for a problem like this would be the following:
#!perl use strict; use warnings; my $i = 0; for (<DATA>) { print if /Paragraph2/ ... /Paragraph/; } __DATA__ Paragraph1: text Paragraph2: text1 text2 text3 Paragraph3: text
Also, if you have fixed-width fields, consider using substr or unpack.
Hope this helped.
CombatSquirrel.

Entropy is the tendency of everything going to hell.

Replies are listed 'Best First'.
Re^2: Regexp help, multiple lines
by 2ge (Scribe) on Aug 15, 2004 at 18:42 UTC
    Hi! thanks for really fast answers, I had some not complete informations in my question, so I updated it. Maybe I should first collect all 'Paragraph' names into array and after them create such regexp ?
    I did know .. and ... operators, but it is nearly same as (.*), it doesn't help here. My regexp should looks like
     /^ {5}\S[^:]+:$\s+([^ {5}\S])/ism
    but ofcourse  '[^ {5}\S]' doesn't work, we know why...:(
      You might want to use something like this
      #!perl use strict; use warnings; my $paragraph = 0; for (<DATA>) { do { ++$paragraph; next; last if $paragraph > 2 } if substr($_, 5, 1) ne ' '; print if $paragraph == 2; } __DATA__ Paragraph1: text Paragraph2: text1 text2 text3 Paragraph3: text
      Hope this helped.
      CombatSquirrel.

      Entropy is the tendency of everything going to hell.
        here is solution, which help me, combining all of your answers, I know name of start Paragraph, but don't know name of end Paragraph, so...THANKS (sorry for mess in replies):

        #!perl use strict; use warnings; my $para = 'Paragraph2:'; while (<DATA>) { print if (/^ {5}$para:?\s*$/i ... /^ {5}\S/ and /^ {7}/) } __DATA__ Paragraph1: text11 Paragraph2: text21 text22 text23 Paragraph3: text31

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://383150]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.