Your problem description makes me suspicious that your regex is taking too many resources in the case you site.

You see, you neglected one of the possible outcomes that becomes much more likely when you use such a horrid regex. The possible outcomes of using a regex are:

I don't understand why you refuse to use a module designed to deal with this type of problem. But at least follow the advice given in the node you reference! I suspect that many of your uses of .*? can be replaced with [^>]* or [^<]*, for example. And something like [^>]*> never has to backtrack.

Each time you use .* or .*?, you give the regex one more place to try backtracking. One such place may mean the regex backtracks over the whole string once. Two such places can end up with the first place backtracking over the whole string and at each point in the string, the second one could backtrack over one side of the string.

So, on a string of length L with B spots in the regex that could require backtracking, you have a potential for run-time propotial to L**B. Such a regex could run very fast when it finds a match but take the full O(L**B) in cases when there is no match to be found.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Problem with CGI script not working (regex at fault) by tye
in thread Problem with CGI script not working (regex at fault) by deryni

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.