Gora, Can you help me with few links that you have handy to which I can refer to build a parser instead of RE
Regards, Davidsanthosh L On Mon, Jan 7, 2013 at 3:38 PM, Gora Mohanty <g...@mimirtech.com> wrote: > On 7 January 2013 15:06, davidsnt <david...@gmail.com> wrote: > > Bangpypers, > > > > Having a little trouble in parsing a file of 702 line appox, > > > > the file is in the format > > > > # > > # <Title> > > # > > [Space] > > [ > > > > Few lines of information about the title > > > > ] > > > > [Space] > > If the above format is strictly followed, this should do it, > assuming you can read the entire file into a string (s in > the example below. > > import re > TITLE_RE = re.compile( r'#\n#([^\n]*)\n#\n \n\[([^\]]*)\]\n \n', > re.MULTILINE|re.DOTALL ) > for m in TITLE_RE.finditer( s.strip ): > title, info = m.groups() > print title, info > > Error handling, and reading chunks from a large file > are left as an exercise for the reader. > > Also, if the file format is at all more complex, and > maybe even in this case, I would write a parser > rather than use regular expressions. > > Regards, > Gora > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers