Community
    • Login

    Regex: How can I change the order of the lines and the sentences after the point? (to reverse the lines or to mix them)

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 1.9k 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.
    • Vasile CarausV Offline
      Vasile Caraus
      last edited by

      hello. I have a file with 400 lines. I want to change the order of the lines and the sentences after point? (to reverse the lines or to mix them). Something like this:

      My mother is home. My father is at work. My sister loves hot milk. My lovely dog is here.
      I go to mall. She seen Jupiter. I read a book. I drove all night.

      My desire output should be (but for 400 lines and sentences):

      My lovely dog is here. My father is at work. My mother is home. My sister loves hot milk.
      I drove all night. She seen Jupiter. I go to mall. I read a book.

      1 Reply Last reply Reply Quote 0
      • Vasile CarausV Offline
        Vasile Caraus
        last edited by

        please consider “point” as “dot”

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

          Hello @vasile-caraus and All,

          I would say :

          SEARCH (?-s)^(.+?\.)\x20(.+?\.)\x20(.+?\.)\x20(.+?\.)$

          REPLACE \4\x20\2\x20\1\x20\3

          Or, if you’re ready to use the sub-routine call syntax (?1), you can modify the search regex as below. The replacement regex is unchanged !

          SEARCH (?-s)^(.+?\.)\x20((?1))\x20((?1))\x20((?1))$

          REPLACE \4\x20\2\x20\1\x20\3

          Notes :

          • The (?1) syntax does not represent what the ^(.+?\.) part matches but, indeed, the true regex .+?\., located between the first block of parentheses !

          • It’s important to point out that the (?1) syntax is not a group, by itself. So the subsequent (?1) syntaxes must be embedded, between a couple of parentheses, in order to define groups 2, 3 and 4

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 2
          • Vasile CarausV Offline
            Vasile Caraus
            last edited by

            @guy038 said:

            \4\x20\2\x20\1\x20\3

            thanks

            1 Reply Last reply Reply Quote 0
            • Vasile CarausV Offline
              Vasile Caraus
              last edited by

              hello Guy, If I have a longer text, such as below, it doesn’t work :) Must change regex on

              Personalitatea regizorului și a scenografului, preocuparile și obligațiile fiecaruia sunt puse in discuție, incercandu-se eludarea dogmatismului maniheist (realism-formalism) din stagiunile anterioare. Peste doi ani, in vara lui 1958, dupa decesul lui Camil Petrescu, tot directivele politicii de partid vor duce la modificarea colegiului și inlocuirea redactorului-șef. Se fac epurari in echipa redacționala, iar unii (Ștefan Augustin Doinaș, Ion D. Sarbu) sunt arestați. Dudu Petrescu joaca fotbal la Dinamo de cand s-a nascut mama lui Rodica.

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA Offline
                Alan Kilborn @Vasile Caraus
                last edited by

                @Vasile-Caraus

                Why would you expect it to work? Your new text has a different kind of pattern to it.

                It would have been a good idea to show the desired AFTER text for the new text, too.

                1 Reply Last reply Reply Quote 0
                • Vasile CarausV Offline
                  Vasile Caraus
                  last edited by

                  I have an alternativ answer, but must be improved:

                  FIND: (.+?\.)(.+?\.)(.+?\.)

                  REPLACE BY: $3$1$2

                  1 Reply Last reply Reply Quote 0
                  • Vasile CarausV Offline
                    Vasile Caraus
                    last edited by

                    I have an alternativ answer, but must be improved:

                    FIND: (^.*)(.+?\.)(.+?\.)(.+?\.)

                    REPLACE BY: $3 $1 $4 $2

                    1 Reply Last reply Reply Quote 0

                    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