Replace numbers in scattered strings to sequential numbers..
-
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)IE;
“Some random thing here”:29,
“Another random thing here”:29,
“Something here”:29,
“Random thing here”:29,
“This value”:39, <!-- I want to change these to be sequential -->
“Some here”:29,
“Other thing here”:29,
“Thing here”:29,
“Some random thing here”:59,
“Another random thing here”:23,
“Something here”:43,
“Random thing here”:2,
“This value”:12, <!-- I want to change these to be sequential -->
“Some here”:18,
“Other thing here”:63,
“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. -
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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login