Community
    • Login

    How to move the second line into the last line in the paragraph?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    20 Posts 4 Posters 660 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.
    • Alan KilbornA
      Alan Kilborn @Reza Saputra
      last edited by

      @Reza-Saputra

      It seems like something like this works on your sample data from the black boxes above:

      find: (?-s)^(\S.+\R)(.+\R)(?!\R)(?s)(.+?\R)(?=\R|\z)
      repl: ${1}${3}${2}
      search mode: Regular expression (of course)

      1 Reply Last reply Reply Quote 2
      • guy038G
        guy038
        last edited by

        Hi, @reza-saputra, @alan-kilborn and all,

        So, seemingly, for any paragraph of more than two lines, you want to move their second line at the end of each current paragraph

        If so, here is an alternative to the @alan-kilborn’s solution :

        SEARCH ^\R.+\R\K(.+\R)((?:.+\R)+)(?=\R|\h*\z)

        REPLACE \2\1


        Notes :

        • First, backup your file(s) !

        • Tick the Wrap around option

        • Select the Regular expression search mode

        • Click once on the Replace All button ( Do NOT use the Replace button )

        Et voilà !

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • Reza SaputraR
          Reza Saputra
          last edited by

          Thank you for helping me @guy038 and @Alan-Kilborn. But it doesn’t work when I input on the big data/the whole file. I can provide the .txt file if you need it.

          1 Reply Last reply Reply Quote 0
          • Robin CruiseR
            Robin Cruise
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • Robin CruiseR
              Robin Cruise
              last edited by Robin Cruise

              By the way, nice topic. I play with this kind of regex, and I find another solution for something similar.

              FIND: (.+?)"(?s).+\K
              REPLACE BY: \r?1\1

              This regex copies everything from first line, until " and paste it at the end of the file. For example, if I have at line 1:

              What is Lorem Ipsum Lorem Ipsum " is simply dummy text of the printing and typesetting,

              then after using my regex you will get

              What is Lorem Ipsum Lorem Ipsum at the end of the file.

              • But I don’t know how to do the same trick for line 2 or line 3…
              1 Reply Last reply Reply Quote 1
              • guy038G
                guy038
                last edited by guy038

                Hi, @reza-saputra,

                So, as I verified that my regex S/R does work with your provided sample, this means that, in your real text, there are some structures which are not present in your sample and which break down the present regex’s logic !

                So, if you don’t mind, could you send me your file, to my temporary e-mail-address : Be certain that a solution exists !!

                Thanks,

                BR

                guy038

                1 Reply Last reply Reply Quote 1
                • Alan KilbornA
                  Alan Kilborn
                  last edited by

                  If only we could get all regex posters to bypass the forum and email @guy038 their regex problems directly, that would be super! :-)

                  1 Reply Last reply Reply Quote 2
                  • Reza SaputraR
                    Reza Saputra
                    last edited by

                    Thank you so much @guy038 @Alan-Kilborn @Robin-Cruise . I already sent email to @guy038 . I hope we can find a solution. I am very happy to join this community, truly positive community and really helping each other ^^

                    1 Reply Last reply Reply Quote 0
                    • guy038G
                      guy038
                      last edited by

                      Hello, @reza-saputra,

                      Well received your file !

                      One more clarification :

                      Considering the first and last block of your file, containing a header line and ONLY two lines, in the enumeration :

                      Acanthophippium eburneum Kraenzl., Gard. Chron., ser. 3, 20: 266 (1896); Govaerts et al. WCSP. 2021.
                       N. Sumatera, Borneo (Sarawak). SUMATRA, KALIMANTAN.
                       Acanthophippium lycaste Ridl., Sarawak Mus. J. 1(2): 35 (1912).
                      
                      ...
                      ...
                      ...
                      
                      Zeuxine viridiflora (J.J.Sm.) J.J.Sm., Icon. Bogor. 2: 259 (1904); Govaerts et al. WCSP. 2021.
                       Borneo, Jawa, Sulawesi. KALIMANTAN, JAVA, SULAWESI.
                       Haplochilus viridiflorus J.J.Sm., Icon. Bogor.: t. 105 B (1903). Adenostylis viridiflora (J.J.Sm.) Merr., J. Straits Branch Roy. Asiat. Soc. 84(Spec. No.): 141 (1921). Heterozeuxine viridiflora (J.J.Sm.) T.Hashim., Proc. World Orchid Conf. 12: 125 (1987).
                      

                      Do you also want to swap the two lines of the enumeration and obtain this result :

                      Acanthophippium eburneum Kraenzl., Gard. Chron., ser. 3, 20: 266 (1896); Govaerts et al. WCSP. 2021.
                       Acanthophippium lycaste Ridl., Sarawak Mus. J. 1(2): 35 (1912).
                       N. Sumatera, Borneo (Sarawak). SUMATRA, KALIMANTAN.
                      
                      ...
                      ...
                      ...
                      
                      Zeuxine viridiflora (J.J.Sm.) J.J.Sm., Icon. Bogor. 2: 259 (1904); Govaerts et al. WCSP. 2021.
                       Haplochilus viridiflorus J.J.Sm., Icon. Bogor.: t. 105 B (1903). Adenostylis viridiflora (J.J.Sm.) Merr., J. Straits Branch Roy. Asiat. Soc. 84(Spec. No.): 141 (1921). Heterozeuxine viridiflora (J.J.Sm.) T.Hashim., Proc. World Orchid Conf. 12: 125 (1987).
                       Borneo, Jawa, Sulawesi. KALIMANTAN, JAVA, SULAWESI.
                      

                      BR

                      guy038

                      Reza SaputraR 1 Reply Last reply Reply Quote 1
                      • Reza SaputraR
                        Reza Saputra @guy038
                        last edited by

                        Hi @guy038 , yes sir.

                        All the line 2 that contains the name of someplace, i.e. Sumatra, Jawa, Sulawesi, Papua, etc should be to the last line before empty space. Like you did on the black box

                        Sincerely yours,
                        Reza

                        1 Reply Last reply Reply Quote 0
                        • guy038G
                          guy038
                          last edited by guy038

                          Hi, @reza-saputra and All,

                          OK ! So, here is the road map :

                          • Open your file in Notepad++

                          • Do a normal selection of all the text below, between (?x-s) and any LINE-BREAK

                          (?x-s)               #  (x) => FREE SPACING mode and (s) => Regex DOT represents a SINGLE STANDARD char ( NOT a LINE-BREAK char )
                          ^                    #  A beginning of line
                          \x20? \R             #  An EMPTY line OR a BLANK line with a SINGLE SPACE char
                          (?! \x20 )  .+ \R    #  A COMPLETE line with its LINE-BREAK, NOT beginning with a SPACE char ( a HEADER line )
                          \K                   #  RESETS the MATCH attempt, so far
                          (                    #  START of group 1
                            \x20 .+ \R         #    A FIRST line, BEGINNING with a SPACE char
                          )                    #  END of group 1  ( So, it contains the FIRST line of the ENUMERATION )
                          (                    #  START of group 2
                            (?:                #    START of a NON-CAPTURING group
                              \x20 .+ \R       #      Any SUBSEQUENT line, BEGINNING with a SPACE char
                            )+?                #    END of the NON-CAPTURING group, REPEATED as FEW times till ...
                          )                    #  END of group 2 ( So, it contains ALL the OTHER lines of the ENUMERATION )
                          (?= \x20? (\R|\z) )  #  ... the NEAREST EMPTY line or BLANK line, with a SINGLE SPACE char OR
                                               #  ... the VERY LAST line of file WITHOUT any LINE-BREAK
                          
                          • Open the Replace dialog ( Ctrl + H )

                          => The Find what zone should be filled up with the text

                          • Now, type in \2\1 in the Replace with zone

                          • Tick the Wrap around option

                          • Select the Regular expression search mode

                          • Click once on the Replace All button ( Do not use the Replace button ! )

                          => Done ! you should get the message Replace All: 2462 replacements were replaced in entire file


                          In my previous post, I didn’t fully consider that :

                          • The separator lines could be completely empty or contain a single space char only

                          • The “header” lines never begin with a single space char

                          • The lines, from the second to the last, do begin with a single space char

                          Moreover, after the header line, the regex must consider the smallest amount of lines( and not the greatest ! ) till an empty or blank line


                          If you prefer, you may try this other syntax of the same regex S/R, written a single line, which enables you to use the Replace button too, for a step by step replacement :

                          • SEARCH (?x-s) ^ ( \x20? \R (?! \x20 ) .+ \R ) ( \x20 .+ \R ) ( (?: \x20 .+ \R )+? ) (?= \x20? (\R | \z) )

                          • REPLACE \1\3\2


                          Notes :

                          • As we use the free-spacing mode (?x), any true space in the regex is irrelevant and only the \x20 syntax does search for a single space char

                          • The \R syntax refer to any kind of line-break chars ( \r or \n )

                          • The (?-s) modifier means that a regex . char matches a single standard character, only ( not EOL chars )

                          • The \z represents the very last zero-length position in file


                          Here is some additionnal information about thie search S/R :

                          SEARCH   (?x-s)      ^        (   \x20? \R       (?! \x20 )  .+ \R  )    ( \x20 .+ \R )    ( (?:  \x20 .+ \R )+? )    (?= \x20? ( \R | \z ) )
                                                             ¯¯¯¯¯¯¯¯       ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯         ¯¯¯¯¯¯¯¯¯¯        ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯          ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
                                           line START      EMPTY/BLANK line     HEADER line           FIRST line         SUBSEQUENT lines         Next EMPTY/BLANK line
                                                           ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯           ¯¯¯¯¯¯¯¯¯¯         ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯      
                                                                        Group 1                         Group 2               Group 3
                          

                          Best Regards,

                          guy038

                          1 Reply Last reply Reply Quote 3
                          • Reza SaputraR
                            Reza Saputra
                            last edited by

                            Hi @guy038 that’s very awesome! Your RegEx work very well. Thank you so much. Really appreciated it.

                            Is there some way that I can add “===” at the beginning of the last line before empty space?

                            My data:

                            Adenoncos virens Blume, Bijdr. Fl. Ned. Ind.: 381 (1825); Govaerts et al. WCSP. 2021. 
                             W. Malesia. SUMATRA, KALIMANTAN, JAVA.
                             
                            Aerides Lour., Fl. Cochinch.: 525 (1790); Govaerts et al. WCSP. 2021.
                             Aeridium Salisb., Trans. Hort. Soc. London 1: 295 (1812), not validly publ.
                             Orxera Raf., Fl. Tellur. 4: 37 (1838).
                             Trop. & Subtrop. Asia. SUMATRA, KALIMANTAN, JAVA, SULAWESI, LESSER SUNDA ISLANDS. 
                             
                            Aerides huttonii (Hook.f.) J.H.Veitch, Cat. New Beautiful Pl. 1868: 23 (1868); Govaerts et al. WCSP. 2021.
                             Saccolabium huttonii Hook.f., Bot. Mag. 93: t. 5681 (1867).
                             Aerides reversa J.J.Sm., Bull. Jard. Bot. Buitenzorg, sér. 2, 8: 45 (1912).
                             NE. Sulawesi. SULAWESI.
                             
                            Aerides inflexa Teijsm. & Binn., Natuurk. Tijdschr. Ned.-Indië 24: 324 (1862); Govaerts et al. WCSP. 2021.
                             Aerides bernhardiana Rchb.f., Gard. Chron., n.s., 24: 650 (1885).
                             Borneo to Sulawesi. KALIMANTAN, SULAWESI.
                            

                            and i want to change like this

                            Adenoncos virens Blume, Bijdr. Fl. Ned. Ind.: 381 (1825); Govaerts et al. WCSP. 2021. 
                             ===W. Malesia. SUMATRA, KALIMANTAN, JAVA.
                             
                            Aerides Lour., Fl. Cochinch.: 525 (1790); Govaerts et al. WCSP. 2021.
                             Aeridium Salisb., Trans. Hort. Soc. London 1: 295 (1812), not validly publ.
                             Orxera Raf., Fl. Tellur. 4: 37 (1838).
                             ===Trop. & Subtrop. Asia. SUMATRA, KALIMANTAN, JAVA, SULAWESI, LESSER SUNDA ISLANDS. 
                             
                            Aerides huttonii (Hook.f.) J.H.Veitch, Cat. New Beautiful Pl. 1868: 23 (1868); Govaerts et al. WCSP. 2021.
                             Saccolabium huttonii Hook.f., Bot. Mag. 93: t. 5681 (1867).
                             Aerides reversa J.J.Sm., Bull. Jard. Bot. Buitenzorg, sér. 2, 8: 45 (1912).
                             ===NE. Sulawesi. SULAWESI.
                             
                            Aerides inflexa Teijsm. & Binn., Natuurk. Tijdschr. Ned.-Indië 24: 324 (1862); Govaerts et al. WCSP. 2021.
                             Aerides bernhardiana Rchb.f., Gard. Chron., n.s., 24: 650 (1885).
                             ===Borneo to Sulawesi. KALIMANTAN, SULAWESI.
                            

                            It’s kind of hard making own regex, but im on my way to understand ^^

                            Best regards,
                            Reza

                            Alan KilbornA 1 Reply Last reply Reply Quote 0
                            • Alan KilbornA
                              Alan Kilborn @Reza Saputra
                              last edited by

                              @Reza-Saputra said in How to move the second line into the last line in the paragraph?:

                              It’s kind of hard making own regex, but im on my way to understand

                              Prove it.
                              Show what you’ve tried and failed with for your last requested transformation.
                              That’s the way it works here.
                              This is not a data transformation service.
                              This is a helping service.

                              1 Reply Last reply Reply Quote 2
                              • Reza SaputraR
                                Reza Saputra
                                last edited by Reza Saputra

                                Hello @Alan-Kilborn . I failed more than 50 times, then I read @guy038 posts in the past (https://community.notepad-plus-plus.org/topic/16408/need-to-merge-all-lines-before-a-blank-line). and now I can make the data that I want like this bellow ^^

                                2eda3cfe-e104-4fe0-98b3-041518fac430-image.png

                                Still figuring how to move some words between special characters.

                                My data:

                                Bulbophyllum humile Schltr., Repert. Spec. Nov. Regni Veg. Beih. 1: 730 (1913). Hapalochilus humilis (Schltr.) Garay & W.Kittr., Bot. Mus. Leafl. 30: 188 (1985 publ. 1986); Govaerts et al. WCSP. 2021.
                                Papua New Guinea. PAPUA.
                                
                                Bulbophyllum lepanthiflorum Schltr., Repert. Spec. Nov. Regni Veg. Beih. 1: 876 (1913). Lepanthanthe lepanthiflora (Schltr.) Szlach., Richardiana 7: 83 (2007); Govaerts et al. WCSP. 2021.
                                 Bulbophyllum lepanthiflorum var. rivulare Schltr., Repert. Spec. Nov. Regni Veg. Beih. 1: 876 (1913).
                                 Bulbophyllum mystrophyllum Schltr., Repert. Spec. Nov. Regni Veg. 16: 124 (1919).
                                 New Guinea. PAPUA.
                                

                                I want to make into this one:

                                Bulbophyllum humile Schltr., Repert. Spec. Nov. Regni Veg. Beih. 1: 730 (1913). ; Govaerts et al. WCSP. 2021.
                                Hapalochilus humilis (Schltr.) Garay & W.Kittr., Bot. Mus. Leafl. 30: 188 (1985 publ. 1986)
                                Papua New Guinea. PAPUA.
                                
                                Bulbophyllum lepanthiflorum Schltr., Repert. Spec. Nov. Regni Veg. Beih. 1: 876 (1913). ; Govaerts et al. WCSP. 2021.
                                Lepanthanthe lepanthiflora (Schltr.) Szlach., Richardiana 7: 83 (2007)
                                Bulbophyllum lepanthiflorum var. rivulare Schltr., Repert. Spec. Nov. Regni Veg. Beih. 1: 876 (1913).
                                Bulbophyllum mystrophyllum Schltr., Repert. Spec. Nov. Regni Veg. 16: 124 (1919).
                                New Guinea. PAPUA.
                                

                                So I want to move some words in the first line between ). and ; Govaerts into the second line.

                                I already read this, but still failed because i only want to move the words ( between ). and ; Govaerts ) on the first line into the second line

                                Thanks for this community, especially @guy038 ^^

                                Best regards,
                                Reza

                                1 Reply Last reply Reply Quote 0
                                • Reza SaputraR
                                  Reza Saputra
                                  last edited by

                                  After hundreds of trying. I m figure out that I can delete some words between two special characters. So that the best I can do, instead of moving into the next line :(

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post
                                  The Community of users of the Notepad++ text editor.
                                  Powered by NodeBB | Contributors