remove characters
-
Is it possible to remove x number of characters from a given position within lines of text. For example, remove 6 charachters from position 7 in each line. Counting from either the beginnig or end?
-
Is it possible
Yes.
Search Mode = Regular Expression will help.
data:
abcdefghijklmnopqrstuvwxyz 123456789x123456789x123456789x
Counting from either the beginnig …
FIND =
^(.{6}).{6}
^
says “only match at beginning of the line”(
…)
says “save the matched text into a numbered group for later use”.
says “match any character”.{6}
says “match six instances of any character”
REPLACE =
$1
$1
says “replace with the contents of group 1”
REPLACE ALL
data after replacing all:
abcdefmnopqrstuvwxyz 1234563456789x123456789x
Counting from … end?
For a different example, let’s remove 4 characters starting 7 characters before the end (so the
tuvw
and4567
, but keeping the stuff that came before, and keeping the last 3 characters (xyz
and89x
)FIND =
.{4}(.{3})$
REPLACE =$1
The only new syntax here is
$
matches the end of the line, just like^
matched the beginning.data after replacing all:
abcdefghijklmnopqrsxyz 123456789x123456789x12389x
----
Useful References
-
From the “beginning”, it’s probably easier to use column-block selection.
Move your caret to line 1 column 7 and then hold Shift+Alt while pressing arrow keys to define your block that is 6 characters wide and however many lines tall you need.
Once the block is defined, let up on all keys and then tap Delete.If your lines happen to all be the same length, this technique would also work for your “end” request.
There’s also the Edit menu’s “Begin/End Column Select” when you have many lines you need to do this over.
-
Thanks for the help
Not sure if this is going to work where the say 6 characters are different in each line (for example different dates)?
-
@sir-twosheds said in remove characters:
Not sure if this is going to work where the say 6 characters are different in each line (for example different dates)?
Why are you “not sure”? Because my example shows that it replaced
ghijkl
on the first line and789x12
on the second line, which are quite obviously different characters. My description was highly explicit that it matches “six of any character”. That should have provided you with clarity on what was being replaced. And you could have tried it on your own data (with a backup, or using undo, in case there was a problem). There are lots of things in life with large uncertainty attached, but the uncertainty on this should have started quite small, and been taken to nearly 0 once you tried it and saw it worked.And Alan’s was even less uncertain, because his method doesn’t even require a search/replace expression, and is just making use of the powers of column-mode/rectangular selection, so wouldn’t care at all as to what the text looked like.
-
@sir-twosheds It will help us if you give us what you want to start with and the desired result/output
-
Hello, @sir-twosheds and All,
Oh…, I see that it’s already solved by many people !
As said by @peterjones, the
Regular expression
search mode is your friend for such cases !
Let’s suppose this INPUT text, which comes from the
change.log
file of theN++ v.8.7.4
release :Notepad++ v8.7.4 regression-fix & bug-fixes: 1. Fix regression of multi-line tabbar height not updated after closing tabs. 2. Fix the extension defined by user not override language default extensions. 3. Fix encoding of nfo file cannot be changed bug.
-
To delete the
first three
characters of each line, use the following regex S/R :-
SEARCH
(?-s)^.{3}(.*)
-
REPLACE
$1
-
And you get this OUTPUT text :
epad++ v8.7.4 regression-fix & bug-fixes: Fix regression of multi-line tabbar height not updated after closing tabs. Fix the extension defined by user not override language default extensions. Fix encoding of nfo file cannot be changed bug.
-
To delete the
last three
characters, use the following regex S/R :-
SEARCH
(?-s).{3}$
-
REPLACE
Leave EMPTY
-
And you get this OUTPUT text :
Notepad++ v8.7.4 regression-fix & bug-fix 1. Fix regression of multi-line tabbar height not updated after closing ta 2. Fix the extension defined by user not override language default extensio 3. Fix encoding of nfo file cannot be changed b
-
To delete
six
characters fromposition 7
, use the following regex S/R :-
SEARCH
(?-s)^(.{6}).{6}
-
REPLACE
$1
-
And you get this OUTPUT text :
Notepa.7.4 regression-fix & bug-fixes: 1. Fixssion of multi-line tabbar height not updated after closing tabs. 2. Fixxtension defined by user not override language default extensions. 3. Fixing of nfo file cannot be changed bug.
-
To delete
six
characters, starting fromposition 7
from the end, use the following regex SR :-
SEARCH
(?-s).{6}(.{6})$
-
REPLACE
$1
-
And you get this OUTPUT text :
Notepad++ v8.7.4 regression-fix fixes: 1. Fix regression of multi-line tabbar height not updated after c tabs. 2. Fix the extension defined by user not override language defaultsions. 3. Fix encoding of nfo file cannot be d bug.
Best Regards,
guy038
-
-
thanks for all your help but you are all speaking a foreign language. I am a normal computer user not a computer programmer so I have no idea what you are talking about
-
I told you the FIND and REPLACE and the MODE.
Looking at the Replace dialog (Find > Replace), we can then see where each piece of the answer goes:
What I called FIND and @guy038 called SEARCH goes in the Find what field in the dialog. What I and @guy038 each called REPLACE goes in the Replace with field in the dialog. What I called the MODE is the Search Mode set of radio buttons, and that needs to be set to Regular expression (as shown in my screenshot). Then to do the replacement, you hit the Replace All button. This is shown below:
Even if you choose to not try to understand the syntax (despite the fact that @guy038 and I both went to lengths to explain every part of the syntax we shared, and I provided you with links where to learn more), I gave you the exact fill-in-the-blanks to do it without any learning on your point, so you can use either of the answers we gave.
To claim that our answers are not helpful because “I am a normal computer user… so I have no idea what you are talking about” is not reasonable. Our answers provided the FIND and REPLACE fields that you needed, without requiring any understanding of the syntax we told you to use, and only requiring you to be able to figure out that FIND or SEARCH maps to Find what and REPLACE maps to Replace with which is not a difficult ask for a “normal computer user”. It is also lying to yourself about your own abilities – you can figure out how to implement the solutions that @guy038 and I described, as can anyone who can follow reasonable directions. If you choose to lie to yourself and tell yourself that you cannot learn the specifics of the syntax, that is your choice (though a bad one): if you choose to believe that lie, then you can just take the solution we gave you and use it, without learning what it means, meaning that you will not be able to replicate similar results for slight changes in your desires in the future, but it will solve your immediate problem.