Searching a string and extract all occurancies of a substring
Anthra Norell
anthra.norell at tiscalinet.ch
Thu Aug 31 17:02:53 EDT 2006
Nico, perhaps this would be suitable:
>>> s = '''Example text:
This is a test. <link url="/www/folder" target="_self" title=""> A test.
<source id="box"><parameter key="path">/www/mydoc1</parameter></source>
And I need to extraxt /www/mydoc1 and /www/mydoc2 from this text.
<source id="box"><parameter key="path">/foo/bar/doc</parameter></source> ...'''
>>> import SE
>>> Thing_Filter = SE.SE ('<EAT> "~<source id="box"><parameter key="path">(.|\n)*?</parameter></source>~==" | "~<.*?>~= " ')
>>> print Thing_Filter (s).split ()
['/www/mydoc1', '/foo/bar/doc']
If you expect more than one of these sections and need a list of records, it would take no more than an additional split.
You'd find SE here: http://cheeseshop.python.org/pypi/SE/2.2%20beta
Regards
Frederic
----- Original Message -----
From: "Nico Grubert" <nicogrubert at gmail.com>
To: <python-list at python.org>
Sent: Thursday, August 31, 2006 5:44 PM
Subject: Searching a string and extract all occurancies of a substring
> Hi there,
>
> in a text with no carriage returns I need to look for all occurancies of
> this string:
>
> <source id="box"><parameter key="path">...</parameter></source>
>
etc.
More information about the Python-list
mailing list