• Login
Community
  • Login

Replacing many occurences of different text blocks

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 4 Posters 606 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N
    No Nope
    last edited by Mar 3, 2024, 1:25 PM

    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?

    P 1 Reply Last reply Mar 3, 2024, 2:20 PM Reply Quote 0
    • P
      PeterJones @No Nope
      last edited by PeterJones Mar 3, 2024, 2:21 PM Mar 3, 2024, 2:20 PM

      @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 FILES

      And 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

      • Notepad++ Online User Manual: Searching/Regex
      • FAQ: Where to find other regular expressions (regex) documentation
      N 1 Reply Last reply Mar 3, 2024, 3:27 PM Reply Quote 0
      • N
        No Nope @PeterJones
        last edited by Mar 3, 2024, 3:27 PM

        @PeterJones Many thanks! How do I represent [tab] in a regular expression?

        M A 2 Replies Last reply Mar 3, 2024, 4:18 PM Reply Quote 0
        • M
          Mark Olson @No Nope
          last edited by Mar 3, 2024, 4:18 PM

          @No-Nope said in Replacing many occurences of different text blocks:

          How do I represent [tab] in a regular expression?

          \t

          N 1 Reply Last reply Mar 3, 2024, 5:39 PM Reply Quote 0
          • A
            Alan Kilborn @No Nope
            last edited by Mar 3, 2024, 4:22 PM

            @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.)

            N 1 Reply Last reply Mar 3, 2024, 5:38 PM Reply Quote 1
            • N
              No Nope @Alan Kilborn
              last edited by Mar 3, 2024, 5:38 PM

              @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.

              P 1 Reply Last reply Mar 3, 2024, 7:06 PM Reply Quote 0
              • N
                No Nope @Mark Olson
                last edited by Mar 3, 2024, 5:39 PM

                @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.

                1 Reply Last reply Reply Quote 0
                • P
                  PeterJones @No Nope
                  last edited by Mar 3, 2024, 7:06 PM

                  @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.

                  5062f77a-de74-42bf-9fcb-420d42bcd147-image.png

                  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.

                  1 Reply Last reply Reply Quote 1
                  6 out of 8
                  • First post
                    6/8
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors