• Login
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.4k 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.
  • V
    Vasile Caraus
    last edited by Jul 21, 2019, 8:39 AM

    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
    • V
      Vasile Caraus
      last edited by Jul 21, 2019, 10:13 AM

      please consider “point” as “dot”

      1 Reply Last reply Reply Quote 0
      • G
        guy038
        last edited by Jul 21, 2019, 11:16 AM

        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
        • V
          Vasile Caraus
          last edited by Jul 21, 2019, 1:08 PM

          @guy038 said:

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

          thanks

          1 Reply Last reply Reply Quote 0
          • V
            Vasile Caraus
            last edited by Aug 1, 2019, 5:45 AM

            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.

            A 1 Reply Last reply Aug 1, 2019, 12:27 PM Reply Quote 0
            • A
              Alan Kilborn @Vasile Caraus
              last edited by Aug 1, 2019, 12:27 PM

              @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
              • V
                Vasile Caraus
                last edited by Aug 7, 2019, 3:26 PM

                I have an alternativ answer, but must be improved:

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

                REPLACE BY: $3$1$2

                1 Reply Last reply Reply Quote 0
                • V
                  Vasile Caraus
                  last edited by Aug 7, 2019, 3:51 PM

                  I have an alternativ answer, but must be improved:

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

                  REPLACE BY: $3 $1 $4 $2

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