In a nutshell you seem to assume .* will match newlines. It won't without a /s When you add a /s to .* it will match everything, so you generally need .*? to make it less greedy but this involves backtracking and is inefficient. See Death To Dot Star!. Note dot star does have its uses, but there are often better ways to skin your cat. You also use m/\d*\.\d*\./ which will match '..' which is not what you want. It should be \d+ in the context shown.

Essentially all you are doing is grabbing two lines at a time (by the looks). Here are some example approaches. The best one depends on the exact format and consitency of the data. Where possible using the input record separator to chunkify an input stream into records is often the easiest approach. You can often then just split the record to get the bits you want. Anyway:

# example 1 my $flag = 0; while(<DATA>) { next unless $flag or m/^\d+\.\d+/; print; $flag ^= 1; } # example 2 depends on newline before Prototype section # using input record separtator to do the work $/ = "\n\n"; while(<DATA>) { print if m/^\d+\.\d+\./; } # example 3 one of many possible REs local $/; $data = <DATA>; @chunks = $data =~ m/^(\d+\.\d+\.[^\n]+\n[^\n]+\n)/gm; print @chunks; # example 4 yet another way to do it (LIKE YOUR ORIGINAL) local $/; $data = <DATA>; @chunks = $data =~ m/(^\d+\.\d+\..*?(?=Prototype:))/gsm; print @chunks; __DATA__ 5.1. GetTagBytestoWrite This function returns the number of bytes taken by the Tag of the ASN +object. It Scans through the BER/DER encoded String and finds the no +of bytes taken by the Tag of a given ASN.1 Object. Prototype: int GetTagbytestoWrite(unsigned char *tstr,int *count) Parameters: *tstr Contents of the ASN.1 Object in a string *count a pointer to an integer to hold the address of the variable hol +ding the number of bytes the tag value takes to store itself. 5.2. GetLenBytestoWrite This function returns the no of Octets taken by the Length field of a +given ASN.1 Object. It Scans through the BER/DER encoded String and f +inds the no of bytes taken by the Length field of a given ASN.1 Objec +t. Prototype: int GetLenbytestoWrite(unsigned char *pstr,int *count) Parameters: *pstr Contents ..

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: regex help by tachyon
in thread regex help by jai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.