How to replace characters over certain number?
-
Hi,
I have the following problem and I can’t get any further:
I want to truncate text lines like this after 55 characters (with spaces) and replace them with " …".
STOXX Europe 600 Optimised Personal & Household Goods EUR (Acc)
MSCI EM Socially Responsible (Dist)
STOXX Europe 600 Optimised Industrial Goods & Services EUR (Acc)So that the result looks as follows:
STOXX Europe 600 Optimised Personal & Household Goods E …
MSCI EM Socially Responsible (Dist)
STOXX Europe 600 Optimised Industrial Goods & Services …I have tried the following, but it does not work:
Highlights only the first 5 characters^.{5}
Finds “only” the last paragraph, no concrete character limit
\h+\S+$
What must the command look like that it works?
(gladly with a short explanation what each operator does, then I understand the principle better) -
Hello, @till-ehrich and All,
You said :
I want to truncate text lines like this after 55 characters
OK. Now, what about the
56th
character ?If the
56th
char is aspace
char, I suppose that you expect this replacement :1234567890123456789012345678901234567890123456789012345 …
But, if the
56th
char is not aspace
char, like below :1234567890123456789012345678901234567890123456789012345ABDEFG HIJKL MNO
Do you expect this OUTPUT :
1234567890123456789012345678901234567890123456789012345 …
or this OUTPUT :
1234567890123456789012345678901234567890123456789012345ABCDEFG …
Best Regards,
guy038
-
@guy038
Whether there is a space or a character after the 55 character is not important. Then only the rest should be replaced by " …".ABCDE FGHIJ KLMNO ABCDE FGHIJKLMNO ABCDE FGHIJ ... ABCDE FGHIJ ...
If there is a blank character, one would have with a simple solution then
" ..."
at the end, thus with 2 blank characters behind each other. But I can change that in a second step simply with search and replace. -
Hi, @till-ehrich and All,
Ah…, OK. In this case, use the following regex S/R :
-
Open the Replace dialog (
Ctrl + H
) -
SEARCH
(?-s).{55}\K.+
-
REPLACE
\x20\x{2026}
-
Check the
Wrap around
box option, preferably -
Select the
Regular expression
search mode -
Click on the
Replace All
button ( Do not use the Replace button ! )
BR
guy038
-
-
OP probably wants
...
rather than\x{2026}
in the replacement… -
@guy038 said in How to replace characters over certain number?:
(?-s).{55}\K.+
Thank you very much, everything worked great. Tidy lists please the users :-)