When I execute the following code with certain data, it takes a long, long time (~10 seconds on a fairly fast machine) to return.

if ($text =~ /($searchString)/) { $_ = $1; s/!CR!/\n/g; print "$_\n"; } else { print "No match\n"; }

These are the values of $searchString and $text going into the regular expression. I apologize for the length, but this is as much as I've been able to narrow down the problem.

$searchString : (?:.(?!!CR!))*.?-------(?:.(?!!CR!))*.?!CR!(?:.(?!!CR! +))*.?!CR!(?:.(?!!CR!))*.?!CR!(?:.(?!!CR!))*.?node(?:.(?!!CR!))*.?!CR! +(?:.(?!!CR!))*.?id(?:.(?!!CR!))*.?NEW ALERT(?:.(?!!CR!))*.?!CR!(?:.(? +!!CR!))*.?borg(?:.(?!!CR!))*.?!CR!(?:.(?!!CR!))*.?subsys(?:.(?!!CR!)) +*.?!CR!(?:.(?!!CR!))*.?severity(?:.(?!!CR!))*.?!CR!(?:.(?!!CR!))*.?!C +R!(?:.(?!!CR!))*.?nohup(?:.(?!!CR!))*.?!CR!(?:.(?!!CR!))*.?Id(?:.(?!! +CR!))*.?!CR!(?:.(?!!CR!))*.?Team(?:.(?!!CR!))*.?!CR!(?:.(?!!CR!))*.?! +CR!(?:.(?!!CR!))*.?!CR!(?:.(?!!CR!))*.?REPORT(?:.(?!!CR!))*.?Resource +(?:.(?!!CR!))*.?slow -(?:.(?!!CR!))*.? $text : ------------------------------------------------------------!C +R!!CR!11/19/2001 16:20:23!CR!node_name[sanitized]!CR!id[987987] NEW A +LERT!CR!borg[this.also.sanitized]!CR!subsystem[this.too] ERR-5555!CR! +severity[warning] group[sanitized-host]!CR!!CR!nohup /usr/local/bin/n +otreal!CR!Id: 987987!CR!Team[TEST_Services]!CR!!CR!ACTION: Send Voice + Mail to [555-3423 555-9922]!CR!REPORT: Process syslog has crashed " +garbage garbage!CR!-------------------------------------------------- +----------!CR!!CR!

I have been looking at the output generated by use re 'debug'; but without much success. I can see that it seems to loop over the same string over and over, but I'm not sure why.

I would enormously appreciate any insight.

Examine


In reply to Regex runs for too long by examine

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.