Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Steven Bethard wrote: Kent Johnson wrote: for line in raw_data: if line.startswith('RelevantInfo1'): info1 = raw_data.next().strip() elif line.startswith('RelevantInfo2'): info2 = raw_data.next().strip() elif line.startswith('RelevantInfo3'): info3 = raw_data.nex

Re: Multiline regex help

2005-03-03 Thread Steven Bethard
Kent Johnson wrote: for line in raw_data: if line.startswith('RelevantInfo1'): info1 = raw_data.next().strip() elif line.startswith('RelevantInfo2'): info2 = raw_data.next().strip() elif line.startswith('RelevantInfo3'): info3 = raw_data.next().strip() sc

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 3 Mar 2005 12:26:37 -0800, James Stroud <[EMAIL PROTECTED]> wrote: > Have a look at "martel", part of biopython. The world of bioinformatics is > filled with files with structure like this. > > http://www.biopython.org/docs/api/public/Martel-module.html > > James Thanks for the link. Stev

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 16:25:39 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: > Here is another attempt. I'm still not sure I understand what form you want > the data in. I made a > dict -> dict -> list structure so if you lookup e.g. scores['10/11/04']['60'] > you get a list of all > the Relevan

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 13:45:31 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: > > I think if you use the non-greedy .*? instead of the greedy .*, you'll > get this behavior. For example: > > py> s = """\ > ... Gibberish > ... 53 > ... MoreGarbage > [snip a whole bunch of stuff] > ... RelevantInfo

Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Here is another attempt. I'm still not sure I understand what form you want the data in. I made a dict -> dict -> list structure so if you lookup e.g. scores['10/11/04']['60'] you get a list of all the RelevantInfo2 values for Relevant1='10/11/04' and Relevant2='60'. The parser is a simple-minde

Re: Multiline regex help

2005-03-03 Thread Steven Bethard
Yatima wrote: On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: A possible solution, using the re module: py> s = """\ ... Gibberish ... 53 ... MoreGarbage ... 12 ... RelevantInfo1 ... 10/10/04 ... NothingImportant ... ThisDoesNotMatter ... 44 ... RelevantInfo2 ... 22 ..

Re: Multiline regex help

2005-03-03 Thread James Stroud
I found the original paper for Martel: http://www.dalkescientific.com/Martel/ipc9/ On Thursday 03 March 2005 12:26 pm, James Stroud wrote: > Have a look at "martel", part of biopython. The world of bioinformatics is > filled with files with structure like this. > > http://www.biopython.org/docs/a

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 07:14:50 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: > > Here is a way to create a list of [RelevantInfo, value] pairs: > import cStringIO > > raw_data = '''Gibberish > 53 > MoreGarbage > 12 > RelevantInfo1 > 10/10/04 > NothingImportant > ThisDoesNotMatter > 44 > RelevantInfo

Re: Multiline regex help

2005-03-03 Thread James Stroud
Have a look at "martel", part of biopython. The world of bioinformatics is filled with files with structure like this. http://www.biopython.org/docs/api/public/Martel-module.html James On Thursday 03 March 2005 12:03 pm, Yatima wrote: > On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard <[EMAI

Re: Multiline regex help

2005-03-03 Thread Yatima
On Thu, 03 Mar 2005 09:54:02 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: > > A possible solution, using the re module: > > py> s = """\ > ... Gibberish > ... 53 > ... MoreGarbage > ... 12 > ... RelevantInfo1 > ... 10/10/04 > ... NothingImportant > ... ThisDoesNotMatter > ... 44 > ... RelevantI

Re: Multiline regex help

2005-03-03 Thread Steven Bethard
Yatima wrote: Hey Folks, I've got some info in a bunch of files that kind of looks like so: Gibberish 53 MoreGarbage 12 RelevantInfo1 10/10/04 NothingImportant ThisDoesNotMatter 44 RelevantInfo2 22 BlahBlah 343 RelevantInfo3 23 Hubris Crap 34 and so on... Anyhow, these "fields" repeat several times

Re: Multiline regex help

2005-03-03 Thread Kent Johnson
Yatima wrote: Hey Folks, I've got some info in a bunch of files that kind of looks like so: Gibberish 53 MoreGarbage 12 RelevantInfo1 10/10/04 NothingImportant ThisDoesNotMatter 44 RelevantInfo2 22 BlahBlah 343 RelevantInfo3 23 Hubris Crap 34 and so on... Anyhow, these "fields" repeat several times

Multiline regex help

2005-03-03 Thread Yatima
Hey Folks, I've got some info in a bunch of files that kind of looks like so: Gibberish 53 MoreGarbage 12 RelevantInfo1 10/10/04 NothingImportant ThisDoesNotMatter 44 RelevantInfo2 22 BlahBlah 343 RelevantInfo3 23 Hubris Crap 34 and so on... Anyhow, these "fields" repeat several times in a give