• Login
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.
  • P
    PESTICIDer
    last edited by Jul 14, 2021, 9:18 AM

    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
    • E
      Ekopalypse
      last edited by Ekopalypse Jul 14, 2021, 9:29 AM Jul 14, 2021, 9:28 AM

      @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
      • P
        PESTICIDer
        last edited by Jul 14, 2021, 9:54 AM

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

        E 1 Reply Last reply Jul 14, 2021, 10:04 AM Reply Quote 0
        • E
          Ekopalypse @PESTICIDer
          last edited by Jul 14, 2021, 10:04 AM

          @Hynek-Kalhous

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

          1 Reply Last reply Reply Quote 2
          • P
            PESTICIDer
            last edited by Jul 14, 2021, 12:37 PM

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

            E 1 Reply Last reply Jul 14, 2021, 12:46 PM Reply Quote 1
            • E
              Ekopalypse @PESTICIDer
              last edited by Jul 14, 2021, 12:46 PM

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

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