Community
    • 登入

    Replace all and return to the line when the number reaches 3 words in the line !

    已排程 已置頂 已鎖定 已移動 Boycott Notepad++
    5 貼文 2 Posters 1.2k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • nurhan chakirN
      nurhan chakir
      最後由 編輯

      hello i want to replace like this :

      before

      AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE FFFFFFFF JJJJJJJJ HHHHHHHHH
      BBBBBBBB AAAAAAAA HHHHHHHHH DDDDDDDD EEEEEEEE FFFFFFFF JJJJJJJJ CCCCCCCC

      REPLACE ALL TO AND i want RESULTS IS this :

      AFTER REPLACE :

      AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
      EEEEEEEE FFFFFFFF JJJJJJJJ HHHHHHHHH
      BBBBBBBB AAAAAAAA HHHHHHHHH DDDDDDDD
      EEEEEEEE FFFFFFFF JJJJJJJJ CCCCCCCC

      please help me ❤

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

        @nurhan-chakir ,

        In theory, we could help. But you have contradicted yourself, and showed very regular data, which I doubt matches your actual data. This makes it difficult for us to give you a good answer. (We could make guesses, and sometimes we even guess right. But why make us guess?)

        • Contradiction: “when the number reaches 3 words in the line!” vs lines of 8 words becoming lines of 4 words.
        • Too regular: each of your example lines is exactly 8 words.
          • Thus, we don’t know whether you intend every line to be ended after exactly 4 words; or whether you want the number of words cut in half, or something else that is clear in your head, but is left ambiguous because of your example data.
          • Also, we don’t know what you intend in edge cases. If you start with two lines of 6 words each, do you want it to become a line with 4, a line with 2, a line with 4, a line with two? Or do you want it to become three lines of 4?
            one two three four five six
            seven eight nine ten eleven twelve
            
            becomes
            one two three four
            five six
            seven eight nine ten 
            eleven twelve
            
            or does it become:
            one two three four
            five six seven eight 
            nine ten eleven twelve
            
            As you should be able to imagine, those are actually two rather different things.

        Also, as a general rule, use the </> button on the toolbar to format your example text, like I have done, to make it obvious that it’s your example text, and to make sure the forum formatting doesn’t convert characters or lose critical whitespace.

        In general, if you want a good answer to this question, put a little more effort in. And read the advice I will be quoting below.

        ----

        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 plain text using the </> toolbar button or manual Markdown syntax. 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.

        nurhan chakirN 1 條回覆 最後回覆 回覆 引用 2
        • nurhan chakirN
          nurhan chakir @PeterJones
          最後由 編輯

          yes be ended after exactly 4 words
          like this :

          one two three four
          five six seven eight
          nine ten eleven twelve

          I want there to be only 4 words and not letters
          in all lines

          thank you very much sir ❤

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

            @nurhan-chakir ,

            Your specs are still way too vague and you have still ignored my advice. As a result, I doubt this will work for you, but until you put in more effort to ask your question meaningfully, this is all the effort I am willing to put in for you.

            • Find What = ^(\w+)\s+(\w+)\s+(\w+)\s+(\w+)\s+
            • Replace With = $1 $2 $3 $4\r\n
            • Search Mode = regular expression

            When I had the example text,

            AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE FFFFFFFF JJJJJJJJ HHHHHHHHH
            BBBBBBBB AAAAAAAA HHHHHHHHH DDDDDDDD EEEEEEEE FFFFFFFF JJJJJJJJ CCCCCCCC
            one two three four five six
            seven eight nine ten eleven twelve
            

            after I’d done a Replace All or multiple Replace commands,it came up with:

            AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
            EEEEEEEE FFFFFFFF JJJJJJJJ HHHHHHHHH
            BBBBBBBB AAAAAAAA HHHHHHHHH DDDDDDDD
            EEEEEEEE FFFFFFFF JJJJJJJJ CCCCCCCC
            one two three four
            five six seven eight
            nine ten eleven twelve
            

            This does what my interpretation of your question and responses asked for.

            I make no guarantees it will do what you want. As always with regex advice, save/backup any critical data before running someone else’s regex.

            If that doesn’t work, try this one instead

            • Find = (?s).*
            • Replace = \x57\x48\x45\x4E\x20\x41\x53\x4B\x49\x4E\x47\x20\x51\x55\x45\x53\x54\x49\x4F\x4E\x53\x20\x49\x4E\x20\x54\x48\x45\x20\x46\x4F\x52\x55\x4D\x0D\x0A\x47\x49\x56\x45\x20\x42\x45\x54\x54\x45\x52\x20\x45\x58\x41\x4D\x50\x4C\x45\x20\x44\x41\x54\x41\x0D\x0A\x4F\x52\x20\x59\x4F\x55\x20\x57\x49\x4C\x4C\x20\x4E\x4F\x54\x20\x47\x45\x54\x20\x41\x20\x47\x4F\x4F\x44\x20\x52\x45\x47\x45\x58\x2E\x0D\x0A\x49\x20\x48\x4F\x50\x45\x20\x59\x4F\x55\x20\x54\x4F\x4F\x4B\x20\x4D\x59\x20\x41\x44\x56\x49\x43\x45\x20\x41\x4E\x44\x20\x42\x41\x43\x4B\x45\x44\x20\x55\x50\x20\x59\x4F\x55\x52\x20\x44\x41\x54\x41\x2E\x0D\x0A
            • Mode = regular expression

            If you need more help, make sure you pay attention to the advice already given and show effort when asking your question. Good luck.

            nurhan chakirN 1 條回覆 最後回覆 回覆 引用 2
            • nurhan chakirN
              nurhan chakir @PeterJones
              最後由 編輯

              @PeterJones said in Replace all and return to the line when the number reaches 3 words in the line !:

              $1 $2 $3 $4\r\n
              THANK YOU
              ❤❤❤😘😘😘😘😘😘😘

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