Cenk - 2016-02-09

Hi,
I created a script to increment numbers in marked text. It still works if marked text contains characters other than number. For example for following text
<row id="1"/>
<row id="2"/>
<row id="3"/>
<row id="4"/>
<row id="5"/>
Find -> Mark -> select Regular expression and search for id="\d+"
After running script numbers are incremented.

import re
start = editor.getLength()
end = 0
console.clear()
editor.beginUndoAction()   
start = editor.indicatorStart(31, start)
while start >= 0:
    end = editor.indicatorEnd(31, start)
    if start == end == 0:
        break
    console.write("Start: "+ str(start)+"\n")
    console.write("End: "+ str(end)+"\n")
    if editor.indicatorValueAt(31, start) == 0:
        if start == 0:
            break
        start = editor.indicatorStart(31, start-1)
        continue
    text = editor.getTextRange(start, end)
    #console.write("Text: "+text)
    #notepad.messageBox(text)
    matchObj = re.finditer(r'-?\d+', text, re.M|re.I)
    for m in matchObj:
        number = m.group()
        editor.setTargetStart(start+m.start())
        editor.setTargetEnd(start+m.end())
        editor.replaceTarget(str(int(number)+1))
        #if m.start() == 0 or m.end() == len(text):
        console.write("Text: "+number)
        editor.setIndicatorCurrent(31)
        editor.indicatorFillRange(start+m.start(), len(str(int(number)+1)))
    if start == 0:
        break
    start = editor.indicatorStart(31, start-1)
editor.endUndoAction()
 

Last edit: Cenk 2016-02-09