本文介绍了多行正则表达式帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Hey Folks, 我在一堆看起来像这样的文件中有一些信息: Gibberish 53 MoreGarbage 12 RelevantInfo1 10/10/04 NothingImportant ThisDoesNotMatter 44 RelevantInfo2 22 BlahBlah 343 RelevantInfo3 23 Hubris 废话 等... 无论如何,这些字段等等。在给定文件中重复几次( 重复次数因文件而异)。 " RelevantInfo"后面的行号。线条真的是我追求的。理想情况下,我想要这样的东西: RelevantInfo1 = 10/10/04#变量名称实际上并不重要 RelevantInfo3 = 23#它只是用于说明我是什么信息 #试图阻止。 分数[RelevantInfo1] [RelevantInfo3] = 22#来自RelevantInfo2的值 从所有文件中收集。 所以,会有几个这些得分中的每个文件都有一堆 的文件。最终,我有兴趣将它们打印成csv文件但是 一旦被困在我的厄运阵列中就应该相对容易 < cue evil laughter> 。 我有一个相当难看的解决方案 (我使用这个术语*非常*松散) 使用awk和他的faithfail伴侣sed,但我更喜欢 python中的内容。 感谢您的时间。 - McGowan的麦迪逊大道公理: 如果是项目被宣传为低于50美元,你可以打赌它不是19.95美元。Hey Folks,I''ve got some info in a bunch of files that kind of looks like so:Gibberish53MoreGarbage12RelevantInfo110/10/04NothingImportantThisDoesNotMatter44RelevantInfo222BlahBlah343RelevantInfo323HubrisCrap34and so on...Anyhow, these "fields" repeat several times in a given file (number ofrepetitions varies from file to file). The number on the line following the"RelevantInfo" lines is really what I''m after. Ideally, I would like to havesomething like so:RelevantInfo1 = 10/10/04 # The variable name isn''t actually importantRelevantInfo3 = 23 # it''s just there to illustrate what info I''m# trying to snag.Score[RelevantInfo1][RelevantInfo3] = 22 # The value from RelevantInfo2Collected from all of the files.So, there would be several of these "scores" per file and there are a bunchof files. Ultimately, I am interested in printing them out as a csv file butthat should be relatively easy once they are trapped in my array of doom<cue evil laughter>.I''ve got a fairly ugly "solution" (I am using this term *very* loosely)using awk and his faithfail companion sed, but I would prefer something inpython.Thanks for your time.--McGowan''s Madison Avenue Axiom:If an item is advertised as "under $50", you can bet it''s not $19.95.推荐答案 这篇关于多行正则表达式帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-11 13:18