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.

enter image description here

Share:
8,294

Related videos on Youtube

David Williams
Author by

David Williams

Updated on September 18, 2022

Comments

  • David Williams
    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
      DavidPostill about 8 years
      Please edit and provide before and after examples. A few lines for each should be sufficient.
  • David Williams
    David Williams about 8 years
    Thanks, 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
    Dale about 8 years
    You can search for the space in your macro. Do this simple by searching when you record your macro.
  • David Williams
    David Williams about 8 years
    Thanks Dale, That worked well. Just have to learn to think laterally now. -)
  • Dale
    Dale about 8 years
    Awesome. I've had to do that tons of times for cleaning data. Please mark my answer. :)
  • Wolfkin
    Wolfkin about 8 years
    Oh 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
    Dale about 8 years
    RegEx would work as well