Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Delete everything except a word

    Help wanted · · · – – – · · ·
    2
    6
    630
    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-Y
      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 Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @P4R0D-Y last edited by

        @P4R0D-Y :

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

        1 Reply Last reply Reply Quote 3
        • P4R0D-Y
          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 Kilborn 1 Reply Last reply Reply Quote 0
          • Alan Kilborn
            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-Y
              P4R0D-Y last edited by

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

              Answer

              Thanks for your time anyways!

              Alan Kilborn 1 Reply Last reply Reply Quote 0
              • Alan Kilborn
                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
                Copyright © 2014 NodeBB Forums | Contributors