Does anyone know of a way to use a replace function to find a regex and replace with a series of sequential numbers?
I am looking to find a tag in some html text and replace it with a "1", then find the next and replace with a "2", etc.
I saw davegb's example of using a function (https://sourceforge.net/projects/npppythonscript/forums/forum/1199074/topic/4667045)
return 'D' + str(int(m.group(1)) * 2)
But I can't seem to get a counter to pass into the function, or use some kind of global counter within the function.
x = 1
return "<h3>" + str(x) + "</h3>"
x = x + 1
That just replaces everything with "1" because it keeps initializing x=1 each time. Without the X = 1 it doesn't do anything.
To expand upon this, I would also like to have the replacement text referenced from an array using the counter as the index.
would result in:
Log in to post a comment.