3

I got quite the same problem of this guy "Notepad++ Regular Expression add up numbers" i don't know python (shame on me maybe). I got an array :

$_ArrFinal = array("A"=>1, "B" =>2, "C" => 3, "D" => 4, "E"=>4, "F" => "5",...)

I have simplify it but i need to increment all the value above 4 in this array by 1. So i did this like in the answer, but sadly it doesn't seems to work :

def calculate(match):
        return '=>%s)' %(match.group(1)+1)
editor.rereplace('=>([5-9]|[1-9]\d{1,})', calculate)

Any suggestion ?

1
  • Well, I get exceptions all the time, maybe it is a good idea to check this answer approach. Commented Feb 12, 2016 at 16:05

1 Answer 1

4

It seems that the default Python Script installation is not working well. This is what has just worked for me:

  • Install Python Script 1.0.8.0
  • Go to the Plugins -> Python Script -> New Script
  • Select the file name (say, "increment_numbers.py")
  • Place this script there:

Code:

def calculate(match):
    return '%s%s'%(match.group(1), str(int(match.group(2))+1))

editor.rereplace(r'(=>\s*"?)(\d+)', calculate)

Then, just evoke this 'increment_numbers' script.

See the regex demo. The expression matches:

  • (=>\s*"?) - Group 1, => followed with zero or more whitespace symbols (\s*) followed with an optional " (as ? matches one or zero preceding token)
  • (\d+) - Group 2, one or more digits
Sign up to request clarification or add additional context in comments.

2 Comments

It's weird but plugin I installed by Plugin Managed (ver 1.0.6.0) seemed not to work but this one (1.0.8.0) worked well. Thanks.
Yes, 1.0.8.0 works well, that is why I always suggest installing that one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.