Community
    • 登入

    Help - Remove a line from a specific text but keep a part of the text

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    10 貼文 3 Posters 2.3k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • D
      Daniel Daniel
      最後由 編輯

      Hello community, help me to delete a specific line from a text but I want to keep a part of the text.

      Example:

      xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
      xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
      xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]
      xxxxxxxxxx | dddddddddd = [aaaaaaaaaa, ssssssssss]

      I want to delete this pattern | dddddddddd = [aaaaaaaaaa, ssssssssss]
      and keep the xxxxxxxxxx text.

      Thanks.

      PeterJonesP 1 條回覆 最後回覆 回覆 引用 0
      • PeterJonesP
        PeterJones @Daniel Daniel
        最後由 編輯

        @Daniel-Daniel

        • FIND = | dddddddddd = [aaaaaaaaaa, ssssssssss]
        • REPLACE = empty
        • Search Mode = Normal
        • REPLACE ALL

        If that’s not sufficient, you will have to describe your problem more accurately. The advice below will help you ask a better question.

        ----

        Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

        D 1 條回覆 最後回覆 回覆 引用 1
        • D
          Daniel Daniel @PeterJones
          最後由 編輯

          @PeterJones Thanks, it works.

          But the last value ssssssssss are different in all lines, how I remove them but keep the xxxxxxxxxx value?

          PeterJonesP 1 條回覆 最後回覆 回覆 引用 0
          • PeterJonesP
            PeterJones @Daniel Daniel
            最後由 編輯

            @Daniel-Daniel said in Help - Remove a line from a specific text but keep a part of the text:

            But the last value ssssssssss are different in all lines, how I remove them but keep the xxxxxxxxxx value?

            You can use search mode = regular expression (aka, regex) instead of normal mode.

            In regex mode, the [ and ] and | characters have special meanings, so you need to escape them.

            But you don’t tell us any rules, and didn’t follow the advice of giving examples that should and shouldn’t match – ie, you ignored all of my advice above. So once again, you’re leaving us to guess what you want, which won’t likely get you to your solution very quickly.

            But here’s a second guess as to what you want, and a solution that works for that guess: change the FIND to \| dddddddddd = \[aaaaaaaaaa, .*?\] and the Search Mode to Regular Expression (and make sure “. matches newline” is off) – this will delete from the | onward , allowing anything but a newline to come after the comma and before the ] … If you really meant that the dddddddddd, aaaaaaaaaa, and ssssssssss can all be different, then just replace the others with .*? as well… but at some point, it will probably be more generic than you intended.

            If this second guess doesn’t work for you, you will have to follow the advice you’ve already been given before I can do anything more to help.

            D 1 條回覆 最後回覆 回覆 引用 0
            • D
              Daniel Daniel @PeterJones
              最後由 編輯

              @PeterJones Thanks for your help.

              Alejandro Perez | Age = [20] | Sex = [Male] | Phone number = 3009876543
              Carlos Gomez | Age = [20] | Sex = [Male] | Phone number = 3103457629

              I want to keep just the names, Alejandro Perez, Carlos Gomez, etc

              And delete all the additional information | Age = [20] | Sex = [Male] | Phone number = 3009876543 as you can see, the phone number are variable.

              PeterJonesP 1 條回覆 最後回覆 回覆 引用 1
              • PeterJonesP
                PeterJones @Daniel Daniel
                最後由 PeterJones 編輯

                @Daniel-Daniel ,

                Even easier:

                • FIND = \|.*$
                • REPLACE = empty
                • MODE = regular expression
                • REPLACE ALL

                If you had just said in the first place “I want to delete everything after the first | on any line (delete the | too)”, we would have gotten there a lot quicker.

                D 1 條回覆 最後回覆 回覆 引用 3
                • D
                  Daniel Daniel @PeterJones
                  最後由 編輯

                  @PeterJones Thanks, it works.

                  L ML 1 條回覆 最後回覆 回覆 引用 1
                  • L ML
                    L M @Daniel Daniel
                    最後由 L M 編輯

                    @Daniel-Daniel

                    Hi,

                    I need to keep a group while moving it to the line above.

                    I have this:

                    WELLER,
                    IV, 3.

                    I need this:

                    WELLER, IV, 3.

                    I tried this without success:

                    Find: \r\n(\sIV,)
                    Replace: ($0)

                    PeterJonesP 1 條回覆 最後回覆 回覆 引用 0
                    • PeterJonesP
                      PeterJones @L M
                      最後由 編輯

                      @L-M said in Help - Remove a line from a specific text but keep a part of the text:

                      Replace: ($0)

                      $0 is the whole match. You should have used $1 if you wanted just the contents of group #1 from your match.

                      L ML 1 條回覆 最後回覆 回覆 引用 0
                      • L ML
                        L M @PeterJones
                        最後由 L M 編輯

                        @PeterJones Thanks it’s working now.

                        I also figured out some occurences had only the CR from this answer:
                        https://community.notepad-plus-plus.org/post/17010

                        And could modify as this to accomodate:
                        Find: \r(\sIV,)
                        Replace: ($1)

                        1 條回覆 最後回覆 回覆 引用 1
                        • 第一個貼文
                          最後的貼文
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors