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
56thcharacter ?If the
56thchar is aspacechar, I suppose that you expect this replacement :1234567890123456789012345678901234567890123456789012345 …But, if the
56thchar is not aspacechar, like below :1234567890123456789012345678901234567890123456789012345ABDEFG HIJKL MNODo 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 aroundbox option, preferably -
Select the
Regular expressionsearch mode -
Click on the
Replace Allbutton ( 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 :-)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login