I have inputs in the form like below

Data:      01 18 01 23 45 67 89 AB  CD EF FE DC BA 98 76 54
           32 10 01 23 45 67 89 AB  CD EF 02 18 67 89 AB CD
           EF FE DC BA 98 76 54 32  10 01 23 45 67 89 AB CD
           EF FE DC BA 03 10 33 33  33 33 33 33 33 33 44 44
           44 44 44 44 44 44 04 10  44 44 44 44 44 44 44 44
           33 33 33 33 33 33 33 33  05 10 55 55 55 55 55 55
           55 55 66 66 66 66 66 66  66 66 FF 10 66 66 66 66
           66 66 66 66 55 55 55 55  55 55 55 55 FF FF
Le:

Data:      31 32 33 34 FF FF FF FF
Le:

Data:
Le:        16

What I need to do is get the input given for the tag Data:. The problem is that it can be either single or multi-line or no input at all. I need to write a regex that will parse only the Data, not the Le.. Please help me in doing that

This seems to work, I'm looking for a sequence of characters which are not a newline, or a newline followed by a non alphanumeric character.

import re

content = """
Data:      01 18 01 23 45 67 89 AB  CD EF FE DC BA 98 76 54
           32 10 01 23 45 67 89 AB  CD EF 02 18 67 89 AB CD
           EF FE DC BA 98 76 54 32  10 01 23 45 67 89 AB CD
           EF FE DC BA 03 10 33 33  33 33 33 33 33 33 44 44
           44 44 44 44 44 44 04 10  44 44 44 44 44 44 44 44
           33 33 33 33 33 33 33 33  05 10 55 55 55 55 55 55
           55 55 66 66 66 66 66 66  66 66 FF 10 66 66 66 66
           66 66 66 66 55 55 55 55  55 55 55 55 FF FF
Le:

Data:      31 32 33 34 FF FF FF FF
Le:

Data:
Le:        16
"""

for match in re.finditer(r'Data:((?:[^\n]|\n[^\w])*)', content):
    print(repr(match.group(1)))
This article has been dead for over six months. Start a new discussion instead.