I think I need to give everyone more to go on, so here it is. My matching code looks like the following.

while (content =~ m%One(.*?)three(.?)five\s+six(.*?)this%gs) { $var1 = $1 ; $var2 = $2 ; $var3 = $3 ; print "$var1\t$var2\t$var3\n" ; }

It gives me output that looks like you would expect, say, for example:

two   four   seven

When the code hangs, it prints out the same thing, but then nothing more.

Now, I've made the following change in keeping with your suggestion.

while (content =~ m%One(.*?)three(.?)five\s+six(.*?)this%gs) { print(STDERR "[", pos($content), "]") ; $var1 = $1 ; $var2 = $2 ; $var3 = $3 ; print "$var1\t$var2\t$var3\n" ; }

I'm relatively new to PERL and not a professional coder, so I'm not sure what this is supposed to produce, but here's an example of what I am getting.

[ two four seven 48430]

On another match, however, it gives me:

[48226] three more numbers

When it hangs, it gives me the following.

[50757] first three numbers second three numbers third three numbers [51826][52896]

Does this help with understanding the problem?


In reply to Re^2: Regex infinite loop? by Ninth Prince
in thread Regex infinite loop? by Ninth Prince

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.