Community
    • Login

    Replace specific part of the line AFTER the match

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 1.0k 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.
    • PESTICIDerP
      PESTICIDer
      last edited by

      Hello guys,
      could you please help me with this little editing problem?
      A have text file, in which I need to find all hits of a specific string and then I need to edit a part of the line which follows the searched string. Text file is formatted so the positions on the line of the searched and to-be-replaced strings are the same.
      Is it somehow possible with regular expressions?
      Thank you very much!

      484116b9-e4a1-47d5-883b-8575397d5427-image.png

      1 Reply Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse
        last edited by Ekopalypse

        @Hynek-Kalhous

        Yes, if your search string is unique and the number of digits
        between the search term and the term to be replaced is
        consistent, you can do something like this

        find: (?<=Z115 65241.{XXX}).{5}
        replace: WHATEVER

        That would mean I search for Z115 65241 and the following
        XXX (must be replaced by your concrete number) characters
        and get the next 5 characters (.{5} like 82302), which I replace by whatever.

        1 Reply Last reply Reply Quote 3
        • PESTICIDerP
          PESTICIDer
          last edited by

          @Ekopalypse said in Replace specific part of the line AFTER the match:

          (?<=Z115 65241.{XXX}).{5}

          Thank you very much! It will do the job.
          But…would it be possible to improve it a little bit? It would be nice to have one condition there - I would like to replace the 5 characters only if they have specific value. Is it possible to do it somehow easily?
          Thanks again!

          EkopalypseE 1 Reply Last reply Reply Quote 0
          • EkopalypseE
            Ekopalypse @PESTICIDer
            last edited by

            @Hynek-Kalhous

            yes, replace .{5} by that specific number.

            1 Reply Last reply Reply Quote 2
            • PESTICIDerP
              PESTICIDer
              last edited by

              Thank you for answering my dumb questions! It all worked well.

              EkopalypseE 1 Reply Last reply Reply Quote 1
              • EkopalypseE
                Ekopalypse @PESTICIDer
                last edited by

                @Hynek-Kalhous - no problem, happy to help. :-)

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