Community
    • Login

    Regex to replace a specific word

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 744 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.
    • CalimeroC
      Calimero
      last edited by

      Hello everyone,

      Let’s say I must replace “word2” on a document by “word3”, but only when the line starts by “word1”.

      I’m not familiar with regex and less with regex in notepad++.

      So I started do it this way and this part seems to work :
      Find field ==> (?:.word1)(?:.*word2)

      I tried in the replace field ==> (?:.word1)(?:.*word3) but it replaced all the found lines by “(?:.word1)(?:.*word3)”

      Can you please help me to do it ? Something like 10 000 files to check for several replaces needed, I’ll be mad before I end it if I have to do it manually :D

      Debug info :
      Notepad++ v8.4.7 (64-bit)
      Build time : Nov 1 2022 - 23:31:11
      Path : C:\Program Files\Notepad++\notepad++.exe
      Command Line :
      Admin mode : OFF
      Local Conf mode : OFF
      Cloud Config : OFF
      OS Name : Windows 10 Pro (64-bit)
      OS Version : 22H2
      OS Build : 19045.2364
      Current ANSI codepage : 1252
      Plugins :
      MarkdownViewerPlusPlus (0.8.2)
      mimeTools (2.9)
      NppConverter (4.5)
      NppExport (0.4)

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Calimero
        last edited by

        @Calimero

        I think you want this “recipe”:
        https://community.notepad-plus-plus.org/topic/22690/generic-regex-replacing-in-a-specific-zone-of-text

        See if you can make sense of that and how you might apply it to your situation.

        1 Reply Last reply Reply Quote 2
        • CalimeroC
          Calimero
          last edited by

          Thanks for the link. Using this one and some others I was able to do what I wanted … almost

          I wasn’t good enough to deal with all the cases only with regex and I had to modify some cases manually, not a lot fortunately.

          Alan KilbornA 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @Calimero
            last edited by

            @Calimero said in Regex to replace a specific word:

            Using this one and some others I was able to do what I wanted … almost
            I wasn’t good enough to deal with all the cases only with regex and I had to modify some cases manually

            Hopefully it wasn’t a defect/limitation of the technique in the link I provided.

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