Quoth Christian Winter <
thepoet...@arcor.de>:
> Am 17.05.2013 05:46, schrieb cibalo:
> > What I am looking for is the result similar to:
> > $ find testing -type f -name "[a-z]*\.txt"
> > testing/dir.a/dir_b/dir-c/this-is-testing4_org.txt
> > testing/dir.a/dir_b/dir-c/this_is_testing3_org.txt
> > I know it is more easier to find the result this way.
>
> > Now I try with perl regex as:
> > $ ls testing/dir.a/dir_b/dir-c/* | perl -ne '/^(.*\/)([a-z].*)$/;
> > print $1, " - ", $2, "\n";'
> > testing/dir.a/dir_b/ - dir-c/This_is_testing1_org.txt
> > testing/dir.a/dir_b/ - dir-c/This-is-testing2_org.txt
> > testing/dir.a/dir_b/dir-c/ - this_is_testing3_org.txt
> > testing/dir.a/dir_b/dir-c/ - this-is-testing4_org.txt
> > Actually, I want my leftmost greedy quantifier, (.*\/), to be so
> > greedier that it can prevent the first two output items from listing.
It's important to realise that (non-)greediness can never prevent a
pattern from matching, it only changes which parts of the pattern match
which parts of the text. As Damien pointed out, possessiveness, that is
(?>) or .*+, can stop a pattern from matching, but in this case the .*+
in (.*+\/) would run all the way to the end of the string and refuse to
give any up, so you still wouldn't get what you want.
> Two approaches instantly come to my mind:
>
> 1. Modifying the pattern for the filename so it looses
> its greediness, which unfortunately isn't solved by
> adding the non-greedy modifier. A simple solution is
> looking for anything but a slash:
> /^ (.*\/) ([^\/]+) $/x;
That's not the same. What the OP hasn't realised is that '*' in a glob
is not equivalent to .*, it's equivalent to [^/]*. So a simple
translation of the original find pattern would be m!/[a-z][^/]*\.txt$!
Ben