我正在尝试从具有以下格式的文本文件加载浮点数:
# random line of text
# random line of text
# keywordtomatch wordtext, wordtext, wordtext with spaces, 751791.000000, text with alphanumeric characters
# keywordtomatch wordtext, wordtext, wordtext with spaces, 751791.000000, text with alphanumeric characters
# random line of text
# random line of text
到目前为止,我无法让以下/类似的正则表达式适用于我:
^{pr2}$从只包含keywordtomatch
的行中读取浮点数。试图调整我的regex在regex101上没有成功。在
这看起来很简单,但对于像我这样的非裸体经验丰富的人来说不行:),那么一条经验丰富的python可能可以帮助我使用一行代码?在
请假定关键字ToMatch未出现在文件的其他位置。在
从小处开始:
让我们简化文本:
^{pr2}$现在将
txt
行复制到一个文件中它适用于多行匹配的行,跳过不匹配的行
所以剩下的问题就是找出一个正确的模式。在
概括一下:
相关问题 更多 >
编程相关推荐