2

I am converting 4-white-space to single-tab in BBEdit using grep. I am converting white space in Python code to tabs. Following works fine:

find:[^\S\r]{4}   replace:\t

However, why the following is removing carriage return. Should not it give the same result.

find:\s{4} replace:\t
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Supertech
  • 746
  • 1
  • 9
  • 25
  • 1
    You can certainly do this with grep, but BBEdit has a convenient [entab/detab command](http://www.barebones.com/products/bbedit/featurestext.html) (Text -> Entab). – steveax Oct 01 '16 at 21:40

1 Answers1

2

[^\S\r]{4} means "4 characters being either not (not whitespace) or not carriage return: you can simplify it as "4 chars (whitespace or not carriage return)".

But carriage return matches whitespace. So negating \r has no effect: it can be furthermore simplified as 4 whitespaces actually equivalent to \s{4}

So you asked for [\t\n ]{4}

But that doesn't make sense, as no tabulation, carriage return or newline chars should be replaced in your case

you probably want [ ]{4}: 4 explicit space characters only.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219