• Login
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.
  • P
    P4R0D-Y
    last edited by May 26, 2021, 5:58 PM

    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

    A 1 Reply Last reply May 26, 2021, 6:04 PM Reply Quote 0
    • A
      Alan Kilborn @P4R0D-Y
      last edited by May 26, 2021, 6:04 PM

      @P4R0D-Y :

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

      1 Reply Last reply Reply Quote 3
      • P
        P4R0D-Y
        last edited by May 26, 2021, 6:12 PM

        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

        A 1 Reply Last reply May 26, 2021, 6:23 PM Reply Quote 0
        • A
          Alan Kilborn @P4R0D-Y
          last edited by May 26, 2021, 6:23 PM

          @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
          • P
            P4R0D-Y
            last edited by May 26, 2021, 6:52 PM

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

            Answer

            Thanks for your time anyways!

            A 1 Reply Last reply May 26, 2021, 7:01 PM Reply Quote 0
            • A
              Alan Kilborn @P4R0D-Y
              last edited by May 26, 2021, 7:01 PM

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