[wellylug] Procmail recipie problem

Stephen Judd sljudd at paradise.net.nz
Tue Jun 17 22:20:56 NZST 2003


On Tue, 2003-06-17 at 21:13, Jamie Dobbs wrote:

> Obviously this shows I need to do some reading up on regexes - can
> anyone recommend a resource for this (preferably one that I can print
> and read).

Obviously google is your friend, and I'll leave you to do that. However
if you have a copy of the O'Reilly Perl book, that's where I learnt most
of what I know.

I can recommend the Python Regex Howto. This has the added advantage
that if you know Python, you can crank up the Python interpreter and
have a blat while you figure out how it works.

The O'Reilly Owl book is very highly thought of, and I'll probably buy
myself a copy one of these days.

A few of traps for young players that I can think of:
- I think you might have fallen into the first one. If you come from the
DOS world, you are used to thinking of * as a wildcard that matches
anything. In standard Unix regexes, * is a quantifier that says "zero or
more times". ".*" is what matches anything.
- Perl has very much extended the core regex syntax with things like
lookaheads, assertions, ignore-whitespace mode, etc. Many other
environments support "Perl-style regex" these days, but it can trip you
up.
- Annoyingly, ^ means "At the start of a string" in one context and
"anything except these characters in square brackets" in another, which
is confusing when you first get started.
- poor font choices make it easy to accidentally mix up \w and \W, \s
and \S.
- "greediness" seems to be the default in most regex engines, but very
often you want the smallest pattern that matches - learn about the "?"
flag, which stipulates non-greeedy matching.

Stephen




More information about the wellylug mailing list