It is possible it's an XY problem, which is why I gave the example usage. From an external source, we have a large number of regular expressions. Two examples are:
/^C:\\Windows\\Program Files\\blah[0-9]\\setup.exe/ /^C:\\Windows(\\SYSTEM)?\\Foo\\Bar.dll/
The second example is probably most interesting. It matches either C:\\Windows\Foo\Bar.dll or C:\Windows\SYSTEM\Foo\Bar.dll.

The regular expressions are from an external source, so we can't change the fact that we get them in that format. We must recurse through a drive to find files matching the expression.

Suppose we come across the directory C:\Temp\ . Intuitively, we know we don't need to recurse into C:\Temp\ because nothing in that directory can match either regex. Because we don't have a leading match, we should return false immediately. On the other hand, when we come to C:\Windows\, we SHOULD recurse, because it matches the leading part of the regex and we may find a full match if we keep going. This is obvious to the human, the trick is how to tell Perl to skip anything that can't match (even as more characters are added to the END of the string).

I'm trying to think of any way to go "up another level", to see the problem from a higher view, but there really isn't anything I can think of. The regular expressions are externally supplied and we must find files on a drive which match them. For efficiency, we wish to avoid looking for files in directories that can't possibly match. The regex engine does this internally, I believe, but I don't know if it exposes the "matched length" of an unmatched regex to Perl.

PS - I wish I could still log into my account from 2003. :(

In reply to Re^2: Regex partial/leading match by raymorris
in thread Regex partial/leading match by raymorris

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.