Notepad ++正则表达式加号 [英] Notepad++ Regular Expression add up numbers
问题描述
如何对所有这些数字求和或增加一定的值?例如,我的目标是将"中的所有这些数字都增加100,但要实现这一点是有问题的.基本上只是以某种方式将当前数字加+100.
How do I sum or add a certain value to all those numbers? For example my goal is to increase all those numbers inside the "" with 100 but achieving that has been problematic. Basically just somehow sum the current number with +100.
我有以下几行
<devio1="875" devio2="7779" devio3="5635" devio4="154"/>
<devio1="765" devio2="74779" devio3="31535" devio4="544"/>
<devio1="4335" devio2="13" devio3="55635" devio4="1565"/>
通过将此正则表达式与Notepad ++一起使用
By using this regular expression with Notepad++
<devio1="([0-9]+)" devio2="([0-9]+)" devio3="([0-9]+)" devio4="([0-9]+)"/>
我可以找到"中的所有数字,但是找不到将+100加到所有数字中的方法.使用正则表达式的Notepad ++可以完成此任务吗?
I can find all the numbers inside the "" but I cannot find a way to add +100 to all of them. Can this task be achieved with Notepad++ using Regular Expressions?
推荐答案
仅在Notepad ++中使用正则表达式是不可能的.不幸的是,无法在替换模式中执行计算.
That's not possible with the sole use of regular expressions in Notepad++. Unfortunately there's no way to perform calculations in the replacement pattern.
因此,在Notepad ++中完成任务的唯一方法是使用Python Script
插件.
So the only way of accomplishing your task in Notepad++ is with the use of the Python Script
plugin.
- 从
Plugin Manager
或官方网站安装Python Script
插件. -
然后转到
Plugins
>Python Script
>New Script
.选择新文件的文件名(例如add_numbers.py),然后复制以下代码:
- Install
Python Script
plugin from thePlugin Manager
or from the official website. Then go to
Plugins
>Python Script
>New Script
. Choose a filename for your new file (eg add_numbers.py) and copy the code that follows:
def calculate(match):
return 'devio%s="%s"' % (match.group(1), str(int(match.group(2))+100))
editor.rereplace('devio([0-9])="([0-9]+)"', calculate)
运行Plugins
> Python Script
> Scripts
> add_numbers.py
,您的文本将转换为:
Run Plugins
> Python Script
> Scripts
> add_numbers.py
and your text will be transformed to:
<devio1="975" devio2="7879" devio3="5735" devio4="254"/>
<devio1="865" devio2="74879" devio3="31635" devio4="644"/>
<devio1="4435" devio2="113" devio3="55735" devio4="1665"/>
这篇关于Notepad ++正则表达式加号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!