Page 1 of 1

How to replace 1st four spaces ONLY in each line w/ nothing?

Posted: Tue Jan 21, 2014 9:16 pm
by jeffy
I have some java source code that is indented with spaces. But before EVERY line, there are four additional spaces (this is the format required by stackoverflow, in order to post code, so it actually displays like code).

Code: Select all

    /**
       <P>A function.</P>
     **/
    public void myFunction()  {
       for(...)   {
          ...
       }
I am trying to eliminate those first four spaces with "^[FOURSPACES]" --> "", but it's making that replacement repeatedly on every line, which is eliminating too many spaces.

It should result in this

Code: Select all

/**
   <P>A function.</P>
 **/
public void myFunction()  {
   for(...)   {
      ...
   }
but actually results in this

Code: Select all

/**
   <P>A function.</P>
 **/
public void myFunction()  {
   for(...)   {
  ...
   }
Does anyone know how to do this replacement only once per line? Thank you for helping me.

Posted: Tue Jan 21, 2014 10:24 pm
by ben_josephs
Your regex should work, but, as you say, it doesn't. It did in TextPad 6.

Use this instead:
Find what: ^_{4}(.*) [Replace the underscore with a space]
Replace with: $1

Posted: Tue Jan 21, 2014 10:40 pm
by jeffy
Thank you, ben_josephs. I thought it might be a bug. I've reported it.

Posted: Mon Jan 27, 2014 12:50 pm
by bbadmin
Thanks for reporting this bug. It will be fixed in the next upgrade.