Something confusing about non-greedy reg exp match

Ben Finney ben+python at
Mon Sep 7 06:23:34 CEST 2009

George Burdell <gburdell1 at> writes:

> I want to find every occurrence of "money," and for each occurrence, I
> want to scan back to the first occurrence of "hello." How can this be
> done?

By recognising the task: not expression matching, but lexing and
parsing. For which you might find the ‘pyparsing’ library of use

 \         “Science is a way of trying not to fool yourself. The first |
  `\     principle is that you must not fool yourself, and you are the |
_o__)               easiest person to fool.” —Richard P. Feynman, 1964 |
Ben Finney

More information about the Python-list mailing list