By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

Regex Question

P: n/a
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

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.