如何为多个文件中的多行添加注释?

问题描述 投票:0回答:1

我试图在多个 yaml 文件中注释掉 Azure DevOps 管道阶段。我尝试使用

在文件中查找

在Notepad++中,但是不成功。

我正在尝试注释掉以下阶段。

- stage: "check_code"
    jobs:
      - job: "check_code"
        pool:
          vmImage: 'windows-latest'
        steps:
          - template: check_code.yml@templates
            parameters:
              projectName: '$(projectName)'

这就是我想要达到的目标。

# - stage: "check_code"
# jobs:
  # - job: "check_code"
    # pool:
      # vmImage: 'windows-latest'
    # steps:
      # - template: check_code.yml@templates
        # parameters:
          # projectName: '$(projectName)'

当我使用记事本++时,我可以复制查找内容搜索框中的行,但无法复制替换为框中注释掉的多行。

关于如何更换它有什么建议吗?

notepad++
1个回答
0
投票
  • Ctrl+H
  • 查找内容:
    ^(?:(- stage: "check_code"\R)|\G(\h*)(?!-stage)(.+\R))
  • 替换为:
    $2# $1$3
  • 勾选 火柴盒
  • 勾选环绕
  • SELECT 正则表达式
  • 取消勾选
    . matches newline
  • 全部替换

说明:

^                       # beginning of line
    (?:                     # non capture group
        (                       # group 1
            - stage: "check_code"   # literally
            \R                      # any kind of linebreak
        )                       # end group 1
      |                       # OR
        \G                      # restart from last match position
        (\h*)                   # group 2, 0 or more horizontal spaces
        (?!-stage)              # negative lookahead, make sure we haven't -stage after
        (                       # group 3
            .+                      # 1 or more any character
            \R                      # any kind of linebreak
        )                       # end group 3
    )                       # end group

截图(之前):

截图(之后):

© www.soinside.com 2019 - 2024. All rights reserved.