what should egrep '|root' /etc/passwd print?

David Canzi dmcanzi at watdcsu.waterloo.edu
Fri Sep 23 16:02:52 AEST 1988


In article <2894 at jpl-devvax.JPL.NASA.GOV> lwall at jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
>The null string should match anything because the whole idea of regular
>expressions involves rejecting strings that you can't match.  To match /abc/,
>you say "For each of the next N characters, bomb out if it doesn't match.
>Otherwise it matches."  You don't go and change the rules just because N
>happens to be 0 sometimes.

This is a pet peeve of mine.  Many programs do something odd and
irregular with operand values of 0, null strings, empty argument lists,
and so on, often in cases where reasonable and regular ways of handling
such things are obvious.  This became a pet peeve of mine while I was
working on VM/CMS, where you are not allowed to create an empty file
(no records), or an empty record within a file, and where ever a
program might attempt to do so, it must check for it and do some kind
of special handling or other.

Here's another example having to do with regular expressions.  If a
regular expression package won't accept an expression like "aa(|bb)cc",
then a program that generates a regular expression using a sprintf
format of "aa(%s|bb)cc" can't work if that string is ever null.  It
occurred to me that if there was some non-null regular expression that
matches only a null string, then you could use something like:

sprintf(regx, "aa(%s%s|bb)cc", matchnull, string);

to accomplish the purpose without causing the regular expression
routines to object.  All that is necessary is to figure out a value for
matchnull.  Suppose "_" was a regular expression metacharacter that
doesn't match anything.  Then "_*" would match 0 or more occurrences of
strings that match "_" -- but there are no such strings, so only 0
occurrences could be matched.  That is, "_*" would match only null
strings.  Can a regular expression that doesn't match anything be
written?  It seemed so to me.  If "[abc]" matches any character from
the set of characters between the brackets, then "[]", having no
characters between the brackets, shouldn't match anything.  So, matchnull
should be set to "[]*".

Nice theory, but when I tried this out with grep and egrep, they
complained about syntax.

-- 
David Canzi



More information about the Comp.unix.wizards mailing list