Hi, how are you?
In the text file contents, the data is recorded in the following format:
For example, if you want to find only the flawdata * {*} in the data below and import it in the form of a list, it's effective What's the way?
['A' , '1432'], ['B' , '2433']
flawdata A {
mark 10 120
drc 2 2 3 30 00
id 1432
}
flawdata B {
mark 10 220
drc 1 2 3 33 30
id 2433
}
Regular expressions look good.
import re
text = """flawdata A {
mark 10 120
drc 2 2 3 30 00
id 1432
}"""
p = re.compile(r'flawdata (.+) \{(?:.|\n)*id (\d+)*(?:.|\n)*\}')
m = p.search(text)
print(m.groups()) # ('A', '1432')
© 2024 OneMinuteCode. All rights reserved.