Two dimensional regexp matching?

David Goodger goodger at users.sourceforge.net
Sat Jul 27 10:35:47 EDT 2002


Regular expressions can do multi-line searches.  Just include "\n" in your
expression and set the re.MULTILINE flag.  However, such regexps can become
very large and difficult to manage.  You may be better off doing the search
a different way.  You may want to split your data into lists and search
programmatically.  You may want to look into a state machine approach; my
statemachine.py (from http://docutils.sf.net/docutils/statemachine.py) may
be useful.

Some questions to ask yourself: Will you be doing one-off searches (reading
the file each time you do a search), or multiple searches (with the file in
memory)?  How dynamic are your search terms (do you repeat the same search,
or is each search different)?

-- 
David Goodger  <goodger at users.sourceforge.net>  Open-source projects:
  - Python Docutils: http://docutils.sourceforge.net/
    (includes reStructuredText: http://docutils.sf.net/rst.html)
  - The Go Tools Project: http://gotools.sourceforge.net/




More information about the Python-list mailing list