If you want to know the results of each regex match (3 vs 18 as mentioned), then you must run them each in turn and record the results. Thusly, approach 2 is right out.

If your regex to match against are multiline matches, then you're getting down to just a loop over the list of regexes and matching against the whole file each time.


The best thing to do is benchmark the various options (while also ensuring that they return the correct results). In practice, I expect that the quality of the regexes input into your program will make all the difference in performance.

For example, during a set of straightforward substitutions against a huge file that I did a few weeks ago, it spent about 5 seconds to read the input and 5 seconds to write the results back to disk. And it took a total of 10 seconds to run.

On the other hand, if your input regexes are complicated messes with lots of backtracking and exponential time cost, you're hosed no matter what you do.


In reply to Re: Regular Expression (Regex) Sieve by SuicideJunkie
in thread Regular Expression (Regex) Sieve by Wiggins

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.