Well if you want to make that capture fast, you need to guarantee that at no point in the RE will you use a backreference back to that captured pattern.
While danger's pattern could be safely optimized, the following one cannot be:
/foo(.*?)bar and stuff then \1 here/
Remember that matching arbitrary REs with internal backreferences is an NP complete problem. Matching REs without is not, and an efficient solution is a DFA. As I explained to you, it
would be possible to make NFAs efficient on patterns that are solvable by a DFA. But as soon as you start in on capturing and backreferences, you have to throw out pretty much all hope for non-trivial optimizations.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.