[英]How to extract lines between two lines from a text file with python3?
I have this type of data我有这种类型的数据
FIRSTX 300.0000
LASTX 700.0000
NPOINTS 801
FIRSTY 1877.68506
MAXY 1877.68506
MINY 4.84203
XYDATA
300.0000 1877.69
300.5000 1284.56
301.0000 882.726
301.5000 585.898
302.0000 382.904
302.5000 261.405
303.0000 189.027
303.5000 146.89
##### Extended Information
[Comments]
Sample name C7 VS POLY(DA)(DT)_BLANK
I want only this part我只想要这部分
300.0000 1877.69
300.5000 1284.56
301.0000 882.726
301.5000 585.898
302.0000 382.904
302.5000 261.405
303.0000 189.027
303.5000 146.89
How can I do this with Python3?我怎样才能用 Python3 做到这一点?
this is the regex - \d{3}\.\d{4}\s{8}\d{1,4}\.\d{1,3}
这是正则表达式 - \d{3}\.\d{4}\s{8}\d{1,4}\.\d{1,3}
import re
regex = "\d{3}\.\d{4}\s{8}\d{1,4}\.\d{1,3}"
data = """
FIRSTX 300.0000
LASTX 700.0000
NPOINTS 801
FIRSTY 1877.68506
MAXY 1877.68506
MINY 4.84203
XYDATA
300.0000 1877.69
300.5000 1284.56
301.0000 882.726
301.5000 585.898
302.0000 382.904
302.5000 261.405
303.0000 189.027
303.5000 146.89
##### Extended Information
[Comments]
Sample name C7 VS POLY(DA)(DT)_BLANK
"""
for matches in re.findall(regex, data):
print(matches)
the output wiil be: output 将是:
300.0000 1877.69
300.5000 1284.56
301.0000 882.726
301.5000 585.898
302.0000 382.904
302.5000 261.405
303.0000 189.027
303.5000 146.89
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.