Does (([^\n]*[\n]){6})(.*) always matches 6 lines?

That depends on what  . (dot) matches. By default, dot does not match a newline, but the  /s switch, which you appear to be using in your  s///smg substitution regex, causes dot to match everything, including newlines (see Modifiers). That means that  (.*) in the above quoted regex may match a great many lines!

(([^\r?\n]*[\r?\n]){52}).*$2

The  $2 capture variable seems to be part of this regex — it's very hard to read because the code is so dense! I can't think of any circumstance in which this would be correct. Did you mean  \2 instead?

[^\r?\n]  [\r?\n]

These two character classes include the  ? character. Are you aware that  ? has no special meaning in a character class? It simply represents the literal character '?'. These two character classes could be equivalently written as [^?\r\n] and [?\r\n]. Is this what you intend?

In general, your code is so dense as to be unreadable. What is the point of writing this as a one-liner? Do yourself a big favor and write this in a separate source file, with lots of whitespace delimiting various parts of the regex (see  /x in Modifiers). If you (and the monks hereabouts) can see the regex, you (and we) may be better able to see the problems.

Update: I also notice that in your
    s/\\cellx10464\\pard\\plain...\\plain/tttttt$2 $4/smg;
eye-bezoggling one-liner regex, there are some big chunks of literal text, some of which repeat. Were I to re-write this as a source file, I might write something like

my $text = ...; ... my $pard = '\pard\plain\intbl\s0\ql\fi0\li0\ri0'; $text =~ s{ \Q\cellx10464\E \Q$pard\E \Q\sl320\plain\f4\fs20\b\cf0 Patent Information\b0\E ([^\r\n]*[\r\n]){88} .* (EP\d{5,7}) (([^\r\n]*[\r\n]){52}) .* \2 [\r\n]+ ... \Q\cell\E \Q$pard\E \Q\plain\E } {tttttt$2 $4}xmsg; ...
(with maybe some  # comments ... in there also). See Quote and Quote-like Operators for info on the  \Q \E interpolation control escape sequences. (Update: There are also a few examples of the use of  \Q \E in perlretut Part 2, in the section "More on characters, strings, and character classes".)

And of course, always usewarnings; and usestrict; if you write this as a separate file — or even as a one-liner!


Give a man a fish:  <%-{-{-{-<


In reply to Re^7: Regex find and replace involving new line by AnomalousMonk
in thread Regex find and replace involving new line by PRA007

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.