Hello, @dick-adams-0, @alan-kilborn, @peterjones and All,
Here is my solution, which can be applied in all cases of text swapping ;-))
First you add a specific character, NOT YET used in your current file, in front of each concerned block of textThus, if I choose the ― character ( Unicode char HORIZONTAL BAR, \x{2015} ), your INPUT text is temporarily changes to :
―<link rel="prev" href="../d/myfile.htm"> <link rel="next" href="../../../l/a/n/ilandsas.htm"> <link rel="up" href="../../../../../ttl/ttl-i.htm"> ―<link rel="stylesheet" href="../../../../../css/hymn.css"> ―<script src="../../../../../js/jquery.js"></script> <script src="../../../../../js/base.js"></script> <script src="../../../../../js/myscripts.js"></script> ―Then using the regex S/R below :
SEARCH (?xs) ^ ― ( .+? ) ― ( .+? ) ― ( .+? ) ― \R
REPLACE \2\3\1
You’ll get your expected OUTPUT text :
<link rel="stylesheet" href="../../../../../css/hymn.css"> <script src="../../../../../js/jquery.js"></script> <script src="../../../../../js/base.js"></script> <script src="../../../../../js/myscripts.js"></script> <link rel="prev" href="../d/myfile.htm"> <link rel="next" href="../../../l/a/n/ilandsas.htm"> <link rel="up" href="../../../../../ttl/ttl-i.htm">Notes :
You may choose any kind of character to begin a block of text which is to be moved ! For instance, in my previous example, I could have chosen the BULLET char ( \x{2022} ) as shown below : •<link rel="prev" href="../d/myfile.htm"> <link rel="next" href="../../../l/a/n/ilandsas.htm"> <link rel="up" href="../../../../../ttl/ttl-i.htm"> •<link rel="stylesheet" href="../../../../../css/hymn.css"> •<script src="../../../../../js/jquery.js"></script> <script src="../../../../../js/base.js"></script> <script src="../../../../../js/myscripts.js"></script> • This method allows you to select very large multi-lines blocks of text as well as simple single-line blocks too !Here is a general example which deals with 6 blocks of text :
Group 1 contains 3 lines
Group 2 contains 3 lines
Group 3 contains 4 lines
Group 4 contains 1 line
Group 5 contains 2 lines
Group 6 contains 5 lines
So, let’s begin this text with a ¤ character in front of lines A, D, G , K, L and N
¤line A Group 1 Line B Group 1 Line C Group 1 ¤Line D Group 2 Line E Group 2 Line F Group 2 ¤Line G Group 3 Line H Group 3 Line I Group 3 Line J Group 3 ¤Line K Group 4 ¤Line L Group 5 Line M Group 5 ¤Line N Group 6 Line O Group 6 Line P Group 6 Line Q Group 6 Line R Group 6 ¤Then, the following regex S/R :
SEARCH (?xs) ^ ¤ ( .+? ) ¤ ( .+? ) ¤ ( .+? ) ¤ ( .+? ) ¤ ( .+? ) ¤ ( .+? ) ¤ \R
REPLACE \3\4\6\2\5\1
would produce this expected OUTPUT text :
Line G Group 3 Line H Group 3 Line I Group 3 Line J Group 3 Line K Group 4 Line N Group 6 Line O Group 6 Line P Group 6 Line Q Group 6 Line R Group 6 Line D Group 2 Line E Group 2 Line F Group 2 Line L Group 5 Line M Group 5 line A Group 1 Line B Group 1 Line C Group 1Notes :
As you can verify, the resulting order respects the replacement numbering of the groups !
The single line block ( Group 4 ) was moved upwards
The two-lines block ( Group 5 ) has not been moved during the process
As a conclusion, if we don’t use the free-spacing mode ( (?x) ), just TWO rules to remind :
Between the leading part (?s)^ and the trailing part ¤\R, just add, in the search regex, as many ¤(.+?) syntaxes than the number of blocks concerned by the replacement
In the replacement regex, just re-organize your blocks, from 1 to n, whatever you want to ! You could even duplicate some blocks using, from the above example, the replacement syntax \3\4\3\6\2\5\2\1\6 ;-))
Best Regards,
guy038