Notepad++ 如何使用记事本更改括号中的第一个数字++;

Notepad++ 如何使用记事本更改括号中的第一个数字++;,notepad++,Notepad++,我有一个文件如下所示: SizeMinMax: [ 8, 14 ] SizeMinMax: [ 4, 8 ] SizeMinMax: [ 6, 10 ] SizeMinMax: [ 0, 14 ] SizeMinMax: [ 0, 8 ] SizeMinMax: [ 0, 10 ] 等等 我需要为所有条目将括号中的第一个数字设置为0,以便如下所示: SizeMinMax: [ 8, 14 ] SizeMinMax: [ 4, 8 ] SizeMinMax: [ 6, 10 ] SizeMi

我有一个文件如下所示:

SizeMinMax: [ 8, 14 ]
SizeMinMax: [ 4, 8 ]
SizeMinMax: [ 6, 10 ]
SizeMinMax: [ 0, 14 ]
SizeMinMax: [ 0, 8 ]
SizeMinMax: [ 0, 10 ]
等等

我需要为所有条目将括号中的第一个数字设置为0,以便如下所示:

SizeMinMax: [ 8, 14 ]
SizeMinMax: [ 4, 8 ]
SizeMinMax: [ 6, 10 ]
SizeMinMax: [ 0, 14 ]
SizeMinMax: [ 0, 8 ]
SizeMinMax: [ 0, 10 ]

我对正则表达式非常不熟悉,有人能教我需要什么类型的表达式吗?

你可以搜索数字,后跟逗号:
(图片下方的说明)

在替换弹出窗口中,确保切换:

  • 环绕
  • 正则表达式
  • 查找输入内容中,使用:
    \d+(,)

    替换为
    输入中,使用:
    0\1

    查找
    正则表达式的含义:

    \d  - a digit
    +   - any other trailing digits (with the \d, matches 1 or more consecutive digits)
    (,) - capture the comma to use with replace.
    
    0  - a literal zero
    \1 - this is replaced with the comma from the find.
    
    替换为
    regex表示:

    \d  - a digit
    +   - any other trailing digits (with the \d, matches 1 or more consecutive digits)
    (,) - capture the comma to use with replace.
    
    0  - a literal zero
    \1 - this is replaced with the comma from the find.
    

    另一种方法是仅当前面有
    SizeMinMax:
    时,才在打开括号后替换数字

    • Ctrl+H
    • 查找内容:
      sizeminax:\[\h*\K\d+
    • 替换为:
      0
    • 检查环绕
    • 检查正则表达式
    • 全部替换
    说明:

    SizeMinMax: \[  # literally
    \h*             # 0 or more horizontal spaces
    \K              # forget all we have seen until this position
    \d+             # 1 or more digits
    
    屏幕截图(之前):

    SizeMinMax: \[  # literally
    \h*             # 0 or more horizontal spaces
    \K              # forget all we have seen until this position
    \d+             # 1 or more digits
    

    屏幕截图(之后):

    SizeMinMax: \[  # literally
    \h*             # 0 or more horizontal spaces
    \K              # forget all we have seen until this position
    \d+             # 1 or more digits
    

    T回答得很好。我在使用正则表达式时遇到的一个问题是,在不同的上下文中(例如使用不同的应用程序、记事本、Visual Studio等)进行不同的搜索和替换似乎需要稍微不同的正则表达式语法。记事本语法是某种类型的“标准”语法还是特定的“风格”?@ChrisHalcrow…你知道,我不确定,必须检查。根据他们的文档,它声称:
    使用Boost正则表达式引擎
    (当切换正则表达式选项时)下面是这些信息。根据这个链接,Boost也是PCRE兼容的(有一些小偏差)。在软件行业工作了20年,我刚刚发现regex标准是IEEE POSIX,最低的标准符合性是BRE(基本正则表达式)。我不确定Perl兼容正则表达式的位置在哪里?