Hello, @evertdb, @scott-sumner and All,
Here is my contribution to the general padding problem, at end of lines. As in the Scott’s solution, above, it uses two consecutive regex S/R
So, EvertDB, let’s suppose the original test example, below :
;; 1
;; 12
;; 123
;; 1234
;; 12345
;; 123456
;; 1234567
;; 12345678
;; 123456789
;; 1234567890
;; 12345678901
;; 123456789012
;; 1234567890123
;; 12345678901234
;; 123456789012345
;; 1234567890123456
;; 12345678901234567
;; 123456789012345678
;; 1234567890123456789
;; 12345678901234567890
;; 123456789012345678901
As I suppose that the two leading semicolons is the line-comment syntax, in your language, perform, the first S/R, below :
SEARCH (?-s)^;;.+
REPLACE $0 ==============================
Notes :
First, due to the (?-s) syntax, the special dot character will stand, strictly, for any single standard character
Then, in the searched part, we’re just looking for two semicolons, at beginning of lines, followed by a non-null amount of standard characters
In replacement, we, simply, rewrite the complete searched match, followed with a space character and 30 equal signs.
From your example, it happens that the minimum, of equal signs to add, is 21. But, you don’t have to bother about estimating that minimum. Just add a large enough amount of this character, at the end of the replacement regex
So, we get the modified text, below :
;; 1 ==============================
;; 12 ==============================
;; 123 ==============================
;; 1234 ==============================
;; 12345 ==============================
;; 123456 ==============================
;; 1234567 ==============================
;; 12345678 ==============================
;; 123456789 ==============================
;; 1234567890 ==============================
;; 12345678901 ==============================
;; 123456789012 ==============================
;; 1234567890123 ==============================
;; 12345678901234 ==============================
;; 123456789012345 ==============================
;; 1234567890123456 ==============================
;; 12345678901234567 ==============================
;; 123456789012345678 ==============================
;; 1234567890123456789 ==============================
;; 12345678901234567890 ==============================
;; 123456789012345678901 ==============================
Now, we just have to delete the extra equal signs at the end of each line. To do so, this second S/R needs the number of characters, at beginning of each line, after the two semicolons symbols, which must be preserved !
From your example, below, you can, visually, determine that this number is 24 :
;; foo bar ===============
123456789012345678901234
So, we’ll use the following regex S/R, below :
SEARCH (?-s)^;;.{24}\K.+
REPLACE Leave Empty
Notes :
For the first part (?-s), just refer the notes, above
The part ^;;.{24} looks, from beginning of each line ( ^ ), for two semicolons, followed by the next 24 characters
Then the part \K resets the regex engine working position and forgets the immediate previous search
Therefore, the final regex match, is, simply, .+, which stands for any non-null amount of standard characters, after the absolute location 24, till the end of each line
Empty replacement regex means that this ending amount of characters is just deleted
IMPORTANT :
For this second S/R, due to the \K regex feature, you must, exclusively use the Replace All button ( NOT the step-by-step Replace button ! )
And, we obtain the final text, with a lined-up padding of equal characters, at the end of each line :
;; 1 =====================
;; 12 ====================
;; 123 ===================
;; 1234 ==================
;; 12345 =================
;; 123456 ================
;; 1234567 ===============
;; 12345678 ==============
;; 123456789 =============
;; 1234567890 ============
;; 12345678901 ===========
;; 123456789012 ==========
;; 1234567890123 =========
;; 12345678901234 ========
;; 123456789012345 =======
;; 1234567890123456 ======
;; 12345678901234567 =====
;; 123456789012345678 ====
;; 1234567890123456789 ===
;; 12345678901234567890 ==
;; 123456789012345678901 =
Et voilà !
Finally, EvertDB, to be exact, we need to get rid of any empty comment line, located right above each real comment-line. To that purpose, use the regex S/R, below :
SEARCH (?-s)^;;\R(?=^;;.+)
REPLACE Leave Empty
Notes :
For the first part (?-s), just refer the notes, above
The part ^;;\R looks for two semicolons, at beginning of each line, immediately followed by End of Line character(s), whatever it is/they are !
The part (?=........) is a positive look-ahead, in other words, a condition which must be true, for an overall match
The condition, to respect, is the regex ^;;.+, which represents a non-empty comment line, in your language ( two semicolons, followed by a non-mull amount of standard characters, before the end of the line )
Due to empty replacement, the searched regex ( the null-comment line ) is, simply, deleted
Best Regards,
guy038
P.S. :
For padding characters, at beginning of a list, you may refer to the topic, below :
https://notepad-plus-plus.org/community/topic/13988/find-replace-issues/5