ietf-mta-filters
[Top] [All Lists]

Re: variables: greedy or non-greedy matching

2003-04-27 13:34:34


On Thu, Apr 24, 2003 at 07:14:43AM -0700, 
ned(_dot_)freed(_at_)mrochek(_dot_)com wrote:
Um, no. For the very small subset of users sophisticated enough to
write this sort of code themselves, I believe their expectation will
be set by past experience with other matching systems, and these
systems tend to default to greedy matching.

I think even in that sophisticated subset, most people just live
their pattern-matching lives without really thinking about the
difference.

But admittedly, my own expectations are muddy, and, worse,
seem to change with the lexical structure of the pattern.
Speaking naively -- I know that this isn't how things work
or should work --

* If the end of my pattern is part of a grammatical whole, I want
  the wildcard to  be greedy; certainly, I, too, would expect
  "f*o" to fully match "foo", not to stop after the first "o".

* But if the end of my pattern is a delimiter, I tend to implicitly
  expect the expression be defined as something that doesn't
  contain that delimiter, as in the example Kjetil quoted where few
  people would expect the * before a closing > in an e-mail address
  to itself contain another >.

I think what this all says is that what felt to me like a problem
with greed is really a problem with globbing and insufficient
expressiveness of * (regexps have problems, too, once you get
to comments and quoting, but one has to work a little harder to
make things fail.)

So let's stay greedy; thanks for setting me straight!

No problem ;-) And let's also remember that a necessary corollary here
is that the regexp we end up choosing needs to support both greedy and
non-greedy matching.

                                Ned