Try this code ===== import re p = re.compile(r'<SYSLIB>([^<]*)<') s = open("file").read() m = re.search(p, s) if m: res = m.groups()[0] res = res.lstrip("\n") res = res.rstrip("\n") print res
result: ======= %python parser.py Sys Data Sys-Data asdkData Data % Thanks Allan "rh0dium" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi all, > > I have a file which I need to parse and I need to be able to break it > down by sections. I know it's possible but I can't seem to figure this > out. > > The sections are broken by <> with one or more keywords in the <>. > What I want to do is to be able to pars a particular section of the > file. So for example I need to be able to look at the SYSLIB section. > Presumably the sections are > > > <SYSLIB> > Sys Data > Sys-Data > asdkData > Data > <LOGLVS> > Data > Data > Data > Data > <SOME SECTION> > Data > Data > Data > Data > <NETLIST> > Data > Data > Data > Data > <NET> > > So if I wanted to break them down.. > > Sections are broken down by this.. > > secH=pyparsing.LineStart() + pyparsing.Suppress( > pyparsing.Literal("<")) + > pyparsing.OneOrMore(pyparsing.Word(pyparsing.alphanums)) + > pyparsing.Suppress( pyparsing.Literal(">")) > > But how do I say that <SECTIONn> stops at the start of the next > <SECTIONm>? > -- http://mail.python.org/mailman/listinfo/python-list