Replacing many occurences of different text blocks
-
I have files that contain among a lot off other stuff, multiple occurrences of blocks like that:
[space][tab]Affirnations: [space][tab][tab]Requests: [0...1024] [space][tab][tab]Approoved: [0...1024] [space][tab][tab]InActioon: [0...1024] [space][tab][tab]Finished: [0...1024] [space][tab][tab]Rejected: [0...1024] [space][tab][tab]ToFollow: [0...1024]
[1…1024] denotes a number from 0 to 1024
I need to replace them all with[space][tab]Affirnations: [space][tab][tab]Requests: 100 [space][tab][tab]Approoved: 100 [space][tab][tab]InActioon: 0 [space][tab][tab]Finished: 100 [space][tab][tab]Rejected: 0 [space][tab][tab]ToFollow: 0
I have dozens of files, each with hundreds of such blocks.
What is the best way to do this? -
@No-Nope ,
Switch your Search Mode to Regular Expression (at the bottom of the Find in Files dialog). Use
\d+
to match one or more digit characters.To make it easy to do, I would probably do each key (word-colon) as a separate search/replace, so do
FIND:
Requests: \d+
REPLACE:Requests: 100
REPLACE ALL IN FILESAnd then repeat for the other keywords.
If you knew the order of the keywords was always the same, you could use
\r\n
in both the search and replace to indicate a normal Windows CRLF end-of-line sequence to do a multi-line replacement----
Useful References
-
@PeterJones Many thanks! How do I represent [tab] in a regular expression?
-
@No-Nope said in Replacing many occurences of different text blocks:
How do I represent [tab] in a regular expression?
\t
-
@No-Nope said in Replacing many occurences of different text blocks:
How do I represent [tab] in a regular expression?
Please put some amount of effort in yourself before asking questions (such as clicking the first link under Peter’s USEFUL REFERENCES section, and then reading some content, whereby you will obtain an answer to this latest question, and perhaps learn some other things in the process.)
-
@Alan-Kilborn said in Replacing many occurences of different text blocks:
Please put some amount of effort in yourself before asking questions (such as clicking the first link under Peter’s USEFUL REFERENCES section, and then reading some content, whereby you will obtain an answer to this latest question, and perhaps learn some other things in the process.)
Quick to accuse, are we? I did try to find the code for [tab] in npp-user-manual page on regular-expressions, but I only found references to the tabs in the seearch/replace dialogue.
-
@Mark-Olson said in Replacing many occurences of different text blocks:
@No-Nope said in Replacing many occurences of different text blocks:
How do I represent [tab] in a regular expression?
\t
Thanks! I looked but didn’t find it.
-
@No-Nope said in Replacing many occurences of different text blocks:
npp-user-manual page on regular-expressions, but I only found references to the tabs in the seearch/replace dialogue.
Interesting. Yes, there are 68 matches, and the ones near the top of the Searching page are all about which tab of the Find/Replace/Mark dialog you are on – but that’s because the user interface for searching is what’s described first in the Searching page.
But as soon as you go into the actual Regular Expression section of that page, it’s the third match (the other two being “table” and “comfortable”), and it’s a line that literally uses the word “tab” four times.
I’d make it easier to find if I could, but I don’t see any way to better help people find the regular expression syntax for the tab character than to put it in the section on regular expressions and use both “tab” and “character” in the description. I’m sorry that wasn’t enough for you to find it.