[Mailed and mailed.]
On Sat, 11 Jan 1997 08:49:56 -0800, Bill Moseley <moseley(_at_)netcom(_dot_)com>
wrote on Procmail-L:
* ^Subject: *BOUNCE.*\[\/[^]]+
which set MATCH to everything between the pair of '[' and ']'.
They ought to teach regular expressions in primary school.
Definitely. :-)
So why don't I need ".*" to catch all the chars between the "\/" and the
"]"? Is that a function of $MATCH or just a part of regular expressions (I
say $MATCH because anything past the "\/")?
What the current regexp says:
^ Beginning of line
Subject: The string "Subject:"
* Optional spaces (zero or more)
BOUNCE The string "BOUNCE"
.* Optional characters, zero or more of any char
\[ The string "["
\/ Placeholder for $MATCH
[^]]+ One or more of any character except "]"
So this will actually match +up+ +to+ the last character +before+ the
"]" character.
Note that the "+" after the character class [^]] means almost the
same as the "*" you're wondering about. So the expression "[^]]+"
matches roughly the same string as ".*" except it won't accept a
closing brace and it wants at least one character, instead of zero or
more.
And why don't I need to escape the "]" as in
You rarely need backslashes inside character classes. In a regular
expression, most things inside a [] are just themselves, not magical.
(The exceptions to this rule is that the negation operator ^ is
special immediately after the opening brace and the range operator -
is special between two other characters. If you want them literally,
you put them somewhere where they are not special. [-^] matches either
a minus or a caret. [^-] might mean any character except minus. And
thus [^--^] would match any character +not+ between minus and caret in
the ASCII set [which in fact excludes a lot of characters, among them
all the uppercase ones; minus is character number 45 and caret is 94
-- the full range of printing characters is 32 to 127].)
Sincerely, and regexp impared,
Any good beginners' book on Unix will contain a regexp tutorial.
If you're too smart for one of the "Unix for the terminally
illitterate" type of books, check out O'Reilly's books. I can also
recommend Kernighan/Pike: _The Unix Programming Environment_ (altho
it's pretty old), Prentice Hall, 1984.
Hope this helps,
/* era */
--
See <http://www.ling.helsinki.fi/~reriksso/> for mantra, disclaimer, etc.
* If you enjoy getting spam, I'd appreciate it if you'd register yourself
at the following URL: <http://www.ling.helsinki.fi/~reriksso/spam.html>