如何使用Notepad++更改括号中的第一个数字
How to change the first number in brackets with Notepad++
我有一个如下所示的文件:
SizeMinMax: [ 8, 14 ]
SizeMinMax: [ 4, 8 ]
SizeMinMax: [ 6, 10 ]
等等。
我需要将所有条目中括号中的第一个数字设置为 0,因此它看起来像这样:
SizeMinMax: [ 0, 14 ]
SizeMinMax: [ 0, 8 ]
SizeMinMax: [ 0, 10 ]
我的正则表达式真的很烂,有人可以教我我需要什么样的表达式吗?
您可以搜索紧跟逗号的数字:
(图片下方的解释)
在“替换”弹出窗口中,确保切换:
- 环绕
- 正则表达式
在Find what
输入中,使用:\d+(,)
在Replace with
输入中,使用:0
Find what
正则表达式表示:
\d - a digit
+ - any other trailing digits (with the \d, matches 1 or more consecutive digits)
(,) - capture the comma to use with replace.
Replace with
正则表达式表示:
0 - a literal zero
- this is replaced with the comma from the find.
另一种方法是仅当前面有 SizeMinMax:
时才替换左括号后面的数字。
- Ctrl+H
- 查找内容:
SizeMinMax: \[\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: [ 8, 14 ]
SizeMinMax: [ 4, 8 ]
SizeMinMax: [ 6, 10 ]
等等。
我需要将所有条目中括号中的第一个数字设置为 0,因此它看起来像这样:
SizeMinMax: [ 0, 14 ]
SizeMinMax: [ 0, 8 ]
SizeMinMax: [ 0, 10 ]
我的正则表达式真的很烂,有人可以教我我需要什么样的表达式吗?
您可以搜索紧跟逗号的数字:
(图片下方的解释)
在“替换”弹出窗口中,确保切换:
- 环绕
- 正则表达式
在Find what
输入中,使用:\d+(,)
在Replace with
输入中,使用:0
Find what
正则表达式表示:
\d - a digit
+ - any other trailing digits (with the \d, matches 1 or more consecutive digits)
(,) - capture the comma to use with replace.
Replace with
正则表达式表示:
0 - a literal zero
- this is replaced with the comma from the find.
另一种方法是仅当前面有 SizeMinMax:
时才替换左括号后面的数字。
- Ctrl+H
- 查找内容:
SizeMinMax: \[\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
屏幕截图(之前):
截图(后):