Batch file 使用工具替换脚本中的specefique代码

Batch file 使用工具替换脚本中的specefique代码,batch-file,notepad++,Batch File,Notepad++,我有一个包含随机代码的脚本,但我正在记事本++中寻找一种方法,或者寻找一个批处理文件或任何可以替换sepcifque代码的工具,下面是一个示例: Random If this equal that then you soulAd do this and do that therefore.. the code should be executed immediatly --stackb select * from user_error where object_name = name sele

我有一个包含随机代码的脚本,但我正在记事本++中寻找一种方法,或者寻找一个批处理文件或任何可以替换sepcifque代码的工具,下面是一个示例:

Random
If this equal that then you soulAd do this and do that therefore..
the code should be executed immediatly
--stackb

select * from user_error where object_name = name
select * from user_error where table= randomly

case 1 a = b else c=a
--stacke
Begin with the structure of the data and divide the codes
end with what you know
我想替换注释堆栈b和堆栈a之间的单词,因此结果如下所示

Random
If this equal that then you sould do this and do that therefore..
the code should be executed immediatly
--stackb

The codes here has been replaced,
can you do that ?

case 1 a = b else c=a
--stacke
Begin with the structure of the data and divide the codes
end with what you know

“批处理文件”或“记事本+”中是否有代码可用于获取结果?

在“记事本+”中,转到“搜索>替换”菜单(快捷键CTRL+H),然后执行以下操作:

  • 查找内容(请参见下面的说明):

  • 替换:

    $1replaced text$2
    
  • 选择单选按钮“正则表达式”并选中复选框。匹配换行符

  • 然后按
    替换所有

  • 这将转换以下文件:

    Random
    If this equal that then you soulAd do this and do that therefore..
    the code should be executed immediatly
    --stackb
    
    select * from user_error where object_name = name
    select * from user_error where table= randomly
    
    case 1 a = b else c=a
    --stacke
    Begin with the structure of the data and divide the codes
    end with what you know
    
    致:

    正则表达式解释:

    (\-\-stackb.*?)select.+?$\r?\nselect.+?$(\r?\n.*?\-\-stacke)
    
    • \-\-stackb
      匹配字符串
      --stackb
      。这里没有什么特别的,除了转义特殊字符的反斜杠。这意味着
      -
      将被解释为文本
      -
      ,而不是正则表达式特殊字符
    • *?
      匹配任何字符,加上我们激活选项“.matches newline”后的换行符。星号
      *
      是一个用于匹配0次或多次的量词。所以
      *
      意味着匹配任何字符或换行符0次或更多次。当一个量词后面跟一个问号
      时,它会使量词不贪婪,这是一个更高级的话题,但简单地说,这就像对量词说,尽量用
      的最小数量来满足自己
    • (\-\-stackb.*?
      现在您已经理解了正则表达式的含义,可以添加括号以捕获匹配结果。您可以使用特殊变量
      $1
      (或
      \1
      相同)访问结果。正如您所看到的,我们正在替换中使用它
    • select.+?$\r?\n
      这里唯一的新东西是
      $
      ,它匹配行尾和用于查找换行符的特殊字符
      \r
      (回车符),
      \n
      (换行符)。请注意,
      \r
      后面跟着
      量词,表示匹配1或0次

    不错,但您能解释一下代码的含义吗?所以我不知道如何使用它(\-\-stackb.*)选择。+?$\r?\n选择。+?$(\r?\n.*-\-stacke)什么是*?$的意思。。我可以替换一个大的脚本吗?我刚刚编辑了答案并解释了。我希望这有帮助。但老实说,你最好先读一个简单的psxls thanx来解释,但在你的代码中,我必须在每一行中包含第一个worf,如果我有一个大段落,我该如何替换它。?你的代码会有用吗?我写的正则表达式是为了适合你的具体例子。如果要删除
    --stackb
    --stacke
    周围的任何类型的文本,请使用以下命令:find=
    (\-\-stackb)。+?(\-\-stacke)
    ,replace=
    $1\n\nreplace\n\n$2
    Random
    If this equal that then you soulAd do this and do that therefore..
    the code should be executed immediatly
    --stackb
    
    replaced text
    
    case 1 a = b else c=a
    --stacke
    Begin with the structure of the data and divide the codes
    end with what you know