Need help with regular expression

Ben Logan ben at wblogan.net
Sat Dec 8 11:30:02 EST 2001


Hello,

I am writing a program in which I need to search an arbitrary string
and return the part between a certain opening sequence, and a closing
sequence.  This is a relatively common thing for me, and I have yet to
figure out a good way to do it.

Here's a first shot:

regXstr = r"""<<\s+(.+?\s+)>>"""

Here, the beginning delimiter is '<<' and the ending is '>>'.  The
grouping parens are because I want to capture whatever is between the
starting and ending sequences, exclusive of any leading whitespace.
 
The above RE works just fine except that I can't have the ending
sequence in the string.  I want to be able to "escape" the ending
sequence with either double quotes (">>") or single quotes ('>>').

I can't seem to figure out how to do this, though.  Can anyone give me
any ideas?

Thanks,
Ben

-- 
Ben Logan: ben at wblogan dot net
OpenPGP Key KeyID: A1ADD1F0




More information about the Python-list mailing list