[Tutor] Pythonic way to extract delimited substrings

Malcolm Greene python at bdurham.com
Mon Apr 14 19:38:09 CEST 2008

Suggestions on the best way to extract delimited substrings strings from
a larger string?

Background: I have a long multi-line string with expressions delimited
with '<(' and ')>' markers. I would like to extract these substrings and
process them in a loop.

Because the left and right delimiters are different from each other
*and* multi-char strings, it would appear that the .split() method would
not be an appropriate tool for this work.

I know how to do this task with regular expressions, but I'm always
cautious about using a bazooka when a hammer will suffice.

What strategy would you recommend?

1. Write a simple parsing function using string primitives (find,

2. Use regular expressions

3. Use a 3rd party string processing module


More information about the Tutor mailing list