scanf style parsing

Skip Montanaro skip at pobox.com
Thu Sep 27 12:24:42 EDT 2001


    Tim> It's not usually easy to learn regexps, no matter what your
    Tim> background.  I come from C/C++ roots (Turbo C++ 3.0) and TRS-80
    Tim> BASIC before that, and I certainly had no idea what regex's were
    Tim> really for until I looked at Perl.

I think the best way to learn about regular expressions is to use
incremental regular expression searching in Emacs/XEmacs.  Just bind C-s and
C-r to isearch-forward-regexp and isearch-backward-regexp.  Then, every time
you search you're using re's.  Initially you'll just use plain strings, but
eventually start mixing in "." and character classes.  Before you know it
"*" and "+" will be your buddies too.  Once you start adding "\(", "\|" and
"\)" to your repertoire, you will attain enlightenment. ;-)

You'll generally never cook up complex regular rexpressions using
incremental search because you have no convenient way to correct mistakes
and retry, but you will use all the pieces and build up more complex stuff
when you're programming Perl or Python.  Making the leap from Emacs's
old-style re's to POSIX-style re's as Perl and Python use now is fairly
straightforward.  Mostly it involves getting rid of backslashes and learning
about {m,n}, \d, \s and other little shortcuts.  (I still almost never use
\d.  My fingers just type [0-9] automatically.)

maybe-the-best-argument-against-vi-ly, yr's

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list