regex to match a multi line pattern 
Author Message
 regex to match a multi line pattern

all,
   I am trying to match a pattern that has multiple lines. I have
found some success, but have hit the wall...

I need a regex that will match:
21 NOV 02  03:17:57PM
*** Today I found God
00000   24C00000 84000000 00003975 9A970100   *$.........9u....*^M
00010   90160000 30010100 03000558 003FFFFF   *....0......X.?..*^M

but not:
21 NOV 02  03:17:57PM
*** Today I found blah-foo
00000   24C00000 84000000 00003975 9A970100   *$.........9u....*^M
00010   90160000 30010100 03000558 003FFFFF   *....0......X.?..*^M

I have been trying:
while(<FILE>){
        print if /^\d{2}\s{1}\D{3}/ .. /^00010.*/;  
             #PerlFAQ..
            }

But can't seem to get any further.
Thanks in advance for feedback,
Jim



Wed, 11 May 2005 00:03:09 GMT  
 regex to match a multi line pattern

[ Please do not post to the long-defunct comp.lang.perl
  newsgroup. It _reduces_ the readership for your postings.
]

Quote:

>    I am trying to match a pattern that has multiple lines.

None of your patterns have multiple lines.

You want to match a _string_ that has multiple lines.

Quote:
> I need a regex that will match:
> 21 NOV 02  03:17:57PM
> *** Today I found God
> 00000   24C00000 84000000 00003975 9A970100   *$.........9u....*^M
> 00010   90160000 30010100 03000558 003FFFFF   *....0......X.?..*^M

> but not:
> 21 NOV 02  03:17:57PM
> *** Today I found blah-foo
> 00000   24C00000 84000000 00003975 9A970100   *$.........9u....*^M
> 00010   90160000 30010100 03000558 003FFFFF   *....0......X.?..*^M

But you are going to withhold what the criteria is?

   select if contains "G"

   select if contains "od"

   select if contains "God"

   do not select if contains "foo"

   do not select if contains "blah"

   do not select if contains a hyphen

All of those criteria would select the one you want and reject
the one you don't want.

We can only offer poor help to correspond to your poor specification...

Quote:
>         print if /^\d{2}\s{1}\D{3}/ .. /^00010.*/;  

                            ^^^                 ^^
                            ^^^                 ^^

Neither of those parts do anything (useful), so they
should not be there.

   my $record;
   while( <DATA> ){
      $record .= $_ if /^\d{2}\s\D{3}/ .. /^00010/;
      if ( /^00010/ ) {
         print $record if $record !~ /blah-foo/;
#         print $record if $record =~ /God/;
         $record = '';
      }
   }

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Wed, 11 May 2005 01:16:03 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. regex to match a multi line pattern

2. Pattern bug matching whitespace in multi-line match?

3. single line regex and multi-line regex without resetting $/

4. Multi line pattern matches?

5. Multi-line pattern matching?

6. pattern matching in multi-line strings fails under perl4.034

7. Multi-line pattern matching

8. Multi line pattern match

9. Can't Match Multi-Line Pattern

10. Multi-line pattern matching in 5.001n

11. Multi-line regex w/ multi-file loop

12. multiline, multi pattern match

 

 
Powered by phpBB® Forum Software