cristi wrote:
By executing the following statement at the command prompt (linux os)
$ echo " 01" | grep '^ *...$'
the string " 01" (excluding the double quotes) is printed to
the standard output. Can somebody explain the behaviour? Of course,
theoretically the regular expression matches the string, but according
to the documentation it shouldn't. The documentation says that the *
operator is greedy so the regular expression should match all the
space at the beginnign of the string and then (because of the 3 dots)
it should try to match 3 more characters.
I might be wrong, but I think "greedy" means that, for example, "a*b"
will match all of "aaaaaaaaaaaaaaaaaaaab" rather than just the last two
characters (e.g. if using --color), not that it will consume all
possible characters in such a way to prevent a match when only consuming
some would result in a match. IOW, it's greed that isn't especially
relevant to grep where what matters is mainly matched vs. didn't match,
but moreso to things where it matters what part of the string matched
(e.g. sed, syntax highlighters, etc).
--
Matthew
If a signature
is not read by anyone,
does it make a sound?