Tushar
Tushar

Reputation: 499

Evaluate an expression while replacing in Notepad++

Input:
3
9
16

I need an output file which adds a constant 10 to every element in input-

Output:
13
19
26

Is there a quick way to evaluate expressions in Notepad++? I tried a couple of things, including:

Search: [0-9]+
Replace: $0+10

But the output I get is:

3+10
9+10
16+10

Upvotes: 0

Views: 319

Answers (1)

Toto
Toto

Reputation: 91518

You can run a python script within the PythonScript plugin.

If it is not yet installed, follow this guide

Create a script (Plugins >> PythonScript >> New Script)

Copy this code and save the file (for example calculate.py):

import re
def calculate(match):
    return '%s' % (str(int(match.group(1)) + 10))

editor.rereplace('(\d+)', calculate)
  • Open the file you want to change
  • Run the script (Plugins >> PythonScript >> Scripts >> calculate)
  • Done

Upvotes: 1

Related Questions