Puzzled by A Regexp...
Jonathan I. Kamens
jik at athena.mit.edu
Tue Mar 5 10:43:50 AEST 1991
In article <10469 at ncar.ucar.edu>, tres at virga.rap.ucar.edu (Tres Hofmeister) writes:
|> It grabs entries with one or more members, true, but also grabs
|> entries with no members, e.g. "news:*:6:". I figured that this regexp
|> would match the longest possible string at the beginning of a line,
|> terminated by a colon, which in the group file should include the first
|> two colons, followed by at least one character. It seems to be doing
|> something else, given that it will also match a line with no members.
Each segment of a regular expression matches the longest possible string
that it can match *while allowing the rest of the regular expression to match
as well*.
So, let's analyze what happens when the regexp "^.*:..*" is compared to
"news:*:6:". It will first match the colon in that regexp against the last
colon in the string. But then it will discover that when it does that, the
rest of the regexp can't be matched. So it will back off and see if "^.*:"
can be matched against something shorter. As a result, the colon will get
matched up with the second to last colon in the string, and the "..*" will
match against "6:".
I hope this clears things up for you.
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.shell
mailing list