Community
    • Login

    Replacing many occurences of different text blocks

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 4 Posters 604 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.
    • No NopeN
      No Nope
      last edited by

      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?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @No Nope
        last edited by PeterJones

        @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
        No NopeN 1 Reply Last reply Reply Quote 0
        • No NopeN
          No Nope @PeterJones
          last edited by

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

          Mark OlsonM Alan KilbornA 2 Replies Last reply Reply Quote 0
          • Mark OlsonM
            Mark Olson @No Nope
            last edited by

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

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

            \t

            No NopeN 1 Reply Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @No Nope
              last edited by

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

              No NopeN 1 Reply Last reply Reply Quote 1
              • No NopeN
                No Nope @Alan Kilborn
                last edited by

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

                PeterJonesP 1 Reply Last reply Reply Quote 0
                • No NopeN
                  No Nope @Mark Olson
                  last edited by

                  @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
                  • PeterJonesP
                    PeterJones @No Nope
                    last edited by

                    @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
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors