检查文本文件并使用正则表达式查找字符串模式

Examine a text file and find string patterns using regex

我试图逐行遍历文本文件并搜索字符串模式。当我找到字符串时,我想做一个 find/replace,这样我就可以在文件中进行多次更新。以下是我尝试完成的步骤。

第 1 步,搜索 'table_name',并抓取整行文本:

  - class: steps.validate.Validate
    conf:
      schema_def:
        fields:
        - data_type: FLOAT
          name: Month_End_Closing_Price
        - data_type: DATETIME
          name: Month_End_Pricing_Date
    id: standardize
  - class: pipe.steps.load.Load
    end:

好的,经过大量猜测后,我 认为 这个答案应该有帮助,或者至少为您指明了正确的方向。

如前所述,您想使用 yaml 模块来帮助您。加载配置后,它实际上只是一个嵌套的 list/dict,很像 json,您可以在其中轻松操作数据。 [这是我尝试复制您的最终结果][1]:

您可以尝试使用数据结构,但使用它应该会给您 很多 比正则表达式更多的自由。