Regex Question

  • Thread starter Thomas =?ISO-8859-15?Q?G=FCttler?=
  • Start date
T

Thomas =?ISO-8859-15?Q?G=FCttler?=

Hi!

I want to parse a file that looks like this:

a0001: basbasdb
asbddsb
asdbasdb
abasbd
a0002: fffff
ffff
ffffff
ffff

a???? should be the key and the following lines should
be the value of a dictionary.

My solution looks like this:

regex=re.compile(r'(?:^|\n)(\w\d\d\d\d):((?:.(?!\n\w\d\d\d\d:))*)',
re.DOTALL)
matches=regex.findall(content)
for match in matches:
print match

I think there is a better solution than this, don't you?

thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top