Notepad++ Trying to add a character after ONLY the first space in each line
8,294
- Ctrl+H
- Find what:
^\S+\h\K
- Replace with:
%
- check Wrap around
- check Regular expression
- Replace all
Explanation:
^ # beginning of line
\S+ # 1 or more non space
\h # 1 horizontal space
\K # forget all we've seen until this position
Replacement:
% # the character to insert
Given:
I have 30,000 lines of text that have randon
number of spaces in them. I need to add a character
to just the first SPACE in each line.
Any who can suggest anything would be
greatly appreciated.
Result for given example:
I %have 30,000 lines of text that have randon
number %of spaces in them. I need to add a character
to %just the first SPACE in each line.
Any %who can suggest anything would be
greatly %appreciated.
Related videos on Youtube
Author by
David Williams
Updated on September 18, 2022Comments
-
David Williams almost 2 years
I have 30,000 lines of text that have randon number of spaces in them. I need to add a character to just the first SPACE in each line. Any who can suggest anything would be greatly appreciated.
-
DavidPostill about 8 yearsPlease edit and provide before and after examples. A few lines for each should be sufficient.
-
-
David Williams about 8 yearsThanks, I did try this but the SPACE is not always in the same place on the line. Macro merely counts the movements before adding the character, it does not look for the SPACE in each line. Othe.rwise that would have worked fine
-
Dale about 8 yearsYou can search for the space in your macro. Do this simple by searching when you record your macro.
-
David Williams about 8 yearsThanks Dale, That worked well. Just have to learn to think laterally now. -)
-
Dale about 8 yearsAwesome. I've had to do that tons of times for cleaning data. Please mark my answer. :)
-
Wolfkin about 8 yearsOh Dale check out my answer because if you've used a macro like that multiple times you may be interested in learning about the joy of regular expressions yourself.
-
Dale about 8 yearsRegEx would work as well