I have a lot text, and I want to remove the first 4 characters in all lines, then insert a character at the beginning of all lines.
How can I do this using Notepad++?
Search -> Replace, make sure you have "Search Mode" set to "Regular expression"
Find what: ^....
Replace with: Your_new_character
Replace All
That will only work on lines that have at least 4 characters in them, though.
If you press and hold Alt while using the mouse you can select multiple lines at once. So, just press and hold Alt, use your mouse to select the first 4 characters all the way down, hit Backspace, then type the character you want to insert. It'll be applied to all of the lines at once.
You can use the record and playback feature.
This answer assumes you have text on all lines, and that they are at least 4 characters long.
Screenshots
Type Delete, Delete, Delete, Delete, X (or whatever you want), ↓, Home
Use 'find replace' with regular expression look for "\n...." and replace with "\n" (see picture).
Use with caution i.e. if you run that thing twice it will delete twice
\n....
will always miss the first line. You could instead search from the beginning of the line, ie. ^....
The easiest way to do this is to use the regular expression option on the find-and-replace menu.
^.{0,4}(.*)$
as the find-expression.#$1
as the replace expression. (Replace the "#" with whatever character you need. Note that you may need to use an escape sequence for certain characters).^
and $
characters mark the beginning and end of a line. This allows you to search just single lines at a time..
is a wildcard that matches any single character.{0,4}
indicates the number of times we want to match the preceding expression. In this case, {0,4}
means that we are looking for matches of anywhere from 0 to 4 characters (matching is "greedy" so it will try to get four if possible, but will settle for less if there are only, say, two characters available on the line). If you want to exclude blank lines, you could use {1,4}
instead. If you wanted to match only lines with at least four characters, just use {4}
.(.*)
matches the rest of the line. .
is again a wildcard (matches any character), and *
means to match 0 or more times (all the way to the end of the line, denoted by $
). The parentheses (...)
mark this as a "group," which allows us to re-use what it matches in the replace-expression.$
) have special functions. If you wanted to insert the literal dollar-sign character, you would need to use \$
instead of just $
. See the link below for more information.$1
inserts the text that matched the first (and only) group (i.e. the sub-expression inside the parentheses) of the find-expression. In this example, this would be the fifth character of the line and onward.^
) or end-of-line ($
) characters in the replace-expression.The links below has more information about Regular Expressions in Notepad++.
http://docs.notepad-plus-plus.org/index.php/Regular_Expressions