Community
    • Login

    Delete everything except a word

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 2.5k 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.
    • P4R0D-YP
      P4R0D-Y
      last edited by

      Hello guys. I have hours searching for a way in regex to delete everything in a line except a certain text. It will be something like this:

      Before:

      Caracas
      Caracas
      UNUSABLE TEXT Caracas UNUSABLE TEXT
      Caracas

      After:

      Caracas
      Caracas
      Caracas
      Caracas

      I have make so many tests with this:

      Find: .(text_you_need_to_keep).

      Replace: $1

      But i cant get it to work. Pls help me

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @P4R0D-Y
        last edited by

        @P4R0D-Y :

        find: (?-s)^.*?(Caracas).*
        repl: ${1}

        1 Reply Last reply Reply Quote 3
        • P4R0D-YP
          P4R0D-Y
          last edited by

          Thank you for the answer. But idk if something its wrong with the text or what, because it doesnt deletes the other text around the word.

          Captura.PNG

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @P4R0D-Y
            last edited by

            @P4R0D-Y

            I guess you have to explain further because from what I can tell of your screenshot it worked to do what was requested. Now if you really wanted something else, that’s a different story.

            1 Reply Last reply Reply Quote 1
            • P4R0D-YP
              P4R0D-Y
              last edited by

              I make the same question on Stackoverflow and heres the correct answer:

              Answer

              Thanks for your time anyways!

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @P4R0D-Y
                last edited by

                @P4R0D-Y

                I gave you the answer to exactly what you asked here.

                Now, if someone else interpreted your question differently and that interpretation lined up with yours, and worked for you, that’s great I guess.

                Try to ask better questions, I guess is the moral of the story.

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