Regex Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Güttler

    Regex Question

    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.compil e(r'(?:^|\n)(\w \d\d\d\d):((?:. (?!\n\w\d\d\d\d :))*)',
    re.DOTALL)
    matches=regex.f indall(content)
    for match in matches:
    print match

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

    thomas

Working...