scanf style parsing
Tim Hammerquist
tim at vegeta.ath.cx
Thu Sep 27 18:28:16 EDT 2001
Me parece que Skip Montanaro <skip at pobox.com> dijo:
>
> 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. ;-)
I used Emacs briefly and couldn't get the hang of it; besides, vi's
command mode keys were just a bit more mnemonic for me.
> 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.)
All true.
> maybe-the-best-argument-against-vi-ly, yr's
This I don't understand. Where was the argument against vi? vi (at
least vim) uses regex's for it's search; it just uses '/' and '?'
instead of the C-s/C-r mapping you mentioned. It is also a good way for
Perler's to get used to "old-style" re syntax (ie, the one with a lot of
backslashes). <wink>
Cheers,
Tim
--
The two surviving chocolate people copulate desperately, losing
themselves in a melting frenzy of lust, spending the last of their
brief, borrowed lives in a spasm of raspberry cream and fear.
-- Narrator, The Sandman
More information about the Python-list
mailing list