The second example is probably most interesting. It matches either C:\\Windows\Foo\Bar.dll or C:\Windows\SYSTEM\Foo\Bar.dll./^C:\\Windows\\Program Files\\blah[0-9]\\setup.exe/ /^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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |