[Tutor] Pythonic way to extract delimited substrings
kent37 at tds.net
Mon Apr 14 21:02:42 CEST 2008
Malcolm Greene wrote:
> 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.
> What strategy would you recommend?
If you just want to get the text between <( and )>, re.findall() or
re.finditer() is probably the simplest way to do it. If it is more
complicated than that (e.g. nesting, escape chars) then I would probably
look at pyparsing.
More information about the Tutor