Replace numbers in scattered strings to sequential numbers..
Ryad Arlan last edited by Ryad Arlan
OK so the problem is as follows:
There are strings with random values that are scattered throughout the file which i want to change to be sequential.
Find What : “This value”:.*,
Will find these lines but i dont know the regex to replace the numbers or how to tell it to stop after say only 20 instances.
. Will find the end of the string and * will allow any value, a wild card (See regex wildcards)
“Some random thing here”:29,
“Another random thing here”:29,
“Random thing here”:29,
"This value":39, <!-- I want to change these to be sequential -->
“Other thing here”:29,
“Some random thing here”:59,
“Another random thing here”:23,
“Random thing here”:2,
"This value":12, <!-- I want to change these to be sequential -->
“Other thing here”:63,
…<!-- A few thousand lines of code here–>
Thanks in advance to any replies, it isnt anything important but I hope it helps others who might be interested.
I may not reply for some time.
PeterJones last edited by
Search/replace (regex) does not know how to count. So it cannot increment your replacement, and it cannot count how many replacements it has done.
To do that, you need a programming language. If you use a plugin like PythonScript, you can leverage the full power of the Python language and give it the access to the contents of the Notepad++ editor window. If you’re willing to go that route, you can search the forum for add_1 and find a lot of examples for the “add_1” style of pythonscript search-and-increment-replace. For stopping after 20 instances, you can look at the optional final argument of the
editor.rereplace(search, replace[, flags[, startPosition[, endPosition[, maxCount]]]])method.
if you have trouble customizing what you’ve seen elsewhere for your specific situation, show us what you’ve tried, and we might be able to point out where it’s gone wrong.