Need help with replacing all lines matching a number and replacing those numbers every odd/even interval
-
So I have a .json file formatted like this
{ "cumulated": 448, "delay": 0, "download": true, "filenameOverride": "", "getBlacklisted": false, "interval": 1200, "lastCheck": "2022-01-05T16:55:07Z", "lastState": { "count": 4, "since": "2022-01-05T14:55:49Z", "state": "finished" }, "notify": true, "pathOverride": "", "postFilters": [ ], "preciseCumulated": true, "query": { "tags": [ "filter:images", "wxyz" ] }, "sites": [ "google.com" ] }, { "cumulated": 97, "delay": 0, "download": true, "filenameOverride": "", "getBlacklisted": false, "interval": 1200, "lastCheck": "2022-01-05T16:55:09Z", "lastState": { "count": 62, "since": "2022-01-04T08:35:28Z", "state": "finished" }, "notify": true, "pathOverride": "", "postFilters": [ ], "preciseCumulated": true, "query": { "tags": [ "filter:images", "qwerty" ] }, "sites": [ "google.com" ] }, { "cumulated": 47, "delay": 0, "download": true, "filenameOverride": "", "getBlacklisted": false, "interval": 1200, "lastCheck": "2022-01-05T16:55:10Z", "lastState": { "count": 621, "since": "2021-12-26T03:31:30Z", "state": "finished" }, "notify": true, "pathOverride": "", "postFilters": [ ], "preciseCumulated": true, "query": { "tags": [ "filter:images", "wasd" ] }, "sites": [ "google.com" ] },
I want to replace the first occurrence of “interval”: 1200, to “interval”: 1200, then the next occurrence of “interval”: 1200, with “interval”: 2100, till the end of the text document, sort of like creating every odd occurrence with an interval of 1200 and the even occurrences with 2100 any way how I can possibly achieve this?
-
In native Notepad++ search/replace regular expressions – there is no “counter”, as such, in regular expressions.
If you are willing to use the PythonScript plugin and write a simple script, then it’s easier – search for
add_1
in the forum, and you’ll have plenty of examples of doing math on a number.But actually, since you only have two sets of replacements, it might be doable in regular expressions, depending on how many characters are between the odd interval and the even interval.
If I have the data
prelim "interval": 1200, other: stuff, other: stuff, "interval": 1200, other: stuff, other: stuff, "interval": 1200, other: stuff, other: stuff, "interval": 1200, other: stuff, other: stuff,
then if the cursor is at the top of the page,
FIND =(?s)"interval": 1200,.*?\K"interval": 1200,
REPLACE ="interval": 2100,
MODE = regular expression
REPLACE ALL
it will becomeprelim "interval": 1200, other: stuff, other: stuff, "interval": 2100, other: stuff, other: stuff, "interval": 1200, other: stuff, other: stuff, "interval": 2100, other: stuff, other: stuff,
… which I think is what you want.
In the regex manual, especially study
\K
----
Useful References
-
@peterjones Thanks a lot! did the job better