in reply to Perl Regexp help w/ grep

Greetings all,
Here is my suggestion.
#the following is untested. my @local_files = grep /^$id.*?_arbv_/i, readdir LOCALDIR;
The . matches any character. The * matches the previous character 0 or more times and the ? keeps it from being too greedy (well in concert with * that is) So it matches the shortest amount possible not the longest.

-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Replies are listed 'Best First'.
Re^2: Perl Regexp help w/ grep
by revdiablo (Prior) on Oct 14, 2005 at 19:00 UTC
    the ? keeps it from being too greedy

    I'm curious, what is the purpose of including this in a simple match? Seems to me that it would only make sense if it was a capturing match or a search and replace. Not that there's anything wrong with it, it just seems a bit pointless.

      Perhaps it's an attempt at optimization? A greedy RE will match the entire filename from that point on and then have to back track character by character to determine if there is or isn't a match. By making the RE non-greedy, matching filenames will be found faster.