"Moos Heintzen" <[email protected]> wrote in message news:[email protected]... > Hello Tutors! > > I was trying to make some groups optional in a regular expression, but > I couldn't do it. > > For example, I have the string: > >>>> data = "<price>42</price> sdlfks d f<ship>60</ship> sdf sdf >>>> <title>Title</title>"
[ re attempts stripped] Your data looks like XML. If it is actually well-formed XML, have you tried ElementTree? PythonWin 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32. Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information. >>> from xml.etree import ElementTree as ET >>> data = "<object><price>42</price> sdlfks d f<ship>60</ship> sdf sdf >>> <title>Title</title></object>" >>> t=ET.fromstring(data) >>> t.tag 'object' >>> for e in t.getchildren(): ... print e.tag,e.text ... price 42 ship 60 title Title >>> -Mark _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
