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



  • 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.



  • please consider “point” as “dot”



  • 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



  • @guy038 said:

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

    thanks



  • 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.



  • @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.



  • I have an alternativ answer, but must be improved:

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

    REPLACE BY: $3$1$2



  • I have an alternativ answer, but must be improved:

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

    REPLACE BY: $3 $1 $4 $2


Log in to reply