Community
    • Login

    Delete everything except a word

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 3.3k Views 1 Watching
    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 Offline
      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 Offline
        Alan Kilborn @P4R0D-Y
        last edited by

        @P4R0D-Y :

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

        1 Reply Last reply Reply Quote 3
        • P4R0D-YP Offline
          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 Offline
            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 Offline
              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 Offline
                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

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors